Ver Mensaje Individual
  #2 (permalink)  
Antiguo 09/11/2007, 16:55
sabgto
 
Fecha de Ingreso: noviembre-2007
Mensajes: 2
Antigüedad: 16 años, 5 meses
Puntos: 0
Re: graphics dibuja fuera de área

He descubierto algo.

1.- El objeto que se inserta a "Canvas", debe derivarse de UIComponent.
2.- El objeto debe tener ancho y alto (width/height).
3.- No se debe dibujar fuera de estos límites.

ejemplo:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="initApp()">

<mx:Script>
<![CDATA[

public var myObj:MObj;

public function initApp():void {
myObj = new MObj();
myObj.width = 200;
myObj.height = 200;
myObj.draw();

myCanvas.addChild(myObj);
}

public function movX():void {
myObj.x = sX.value;
}

]]>
</mx:Script>

<mx:Panel x="10" y="10" width="206" height="427" layout="absolute">
<mx:HSlider x="10" y="79" width="166" id="sX"
minimum="0" maximum="300" snapInterval="1" change="movX()"/>
</mx:Panel>
<mx:Canvas x="224" y="10" width="454" height="427" id="myCanvas" backgroundColor="#d5fffd">
</mx:Canvas>

</mx:Application>
************************************************** ***********
package
{
import mx.core.UIComponent;

public class MObj extends UIComponent
{
public function MObj() {
super();
}

public function draw():void {
this.graphics.clear();
this.graphics.lineStyle(2.0, 0xFF0000, 1.0);
this.graphics.drawRect(0, 0, this.width-1, this.height-1);
}
}
}