2006-11-11

Dynamic Drawing AS3



A uma semana respondi sobre o assunto, então resolvi colocar aqui.

A classe retorna um objeto UIComponent extendido que contém um Sprite.

package lib
{
import mx.core.UIComponent;
import flash.display.Sprite;
import flash.events.MouseEvent

public class Circle extends UIComponent{

private var c:Sprite;

public function Circle(){
super();
c = new Sprite();
c.graphics.beginFill(0xFFCC00);
c.graphics.drawCircle(100, 100, 50);
this.addChild(c);
}

private function DownHandler(event:MouseEvent):void
{
var sprite:Sprite = Sprite(event.target);
sprite.startDrag();
}

private function UpHandler(event:MouseEvent):void{
var sprite:Sprite = Sprite(event.target);
sprite.stopDrag();
}

[Inspectable(category="General")]
public function enableDrag(enable:Boolean):void{
if(enable){
c.addEventListener(MouseEvent.MOUSE_DOWN, DownHandler);
c.addEventListener(MouseEvent.MOUSE_UP, UpHandler);
}else{
c.removeEventListener(MouseEvent.MOUSE_DOWN, DownHandler);
c.removeEventListener(MouseEvent.MOUSE_UP, UpHandler);
}
}

}

}

Nenhum comentário: