Creating a reusable effect in ActionScript with Move class
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import flash.events.Event;
import mx.effects.Effect;
import mx.effects.Move;
private var myMove:Move = new Move();
private function playMove(target:Object,newX:Number, newY:Number):void {
myMove.end();
myMove.target = target;
myMove.duration = 4000;
myMove.xTo = newX - target.width/2;
myMove.yTo = newY - target.height/2;
myMove.play();
}
private function handleClick(eventObj:Event):void {
var targetComponent:Object = eventObj.currentTarget;
var parentCont:Object = targetComponent.parent;
playMove(eventObj.target, parentCont.width/2, parentCont.height/2);
}
</mx:Script>
<mx:Canvas width="200" height="200">
<mx:Button id="myButton" label="Center me" click="handleClick(event);" />
</mx:Canvas>
</mx:Application>
Related examples in the same category