topical media & game development
sample-flex-sprite-animation.mx
sample-flex-sprite-animation.mx
[swf]
flex
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
script / click to start
<mx:Script>
<![CDATA[
import mx.core.UIComponent; // only needed if you use the second method
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public var circle:Sprite;
init(s)
public function init():void{
circle = new Sprite();
circle.graphics.beginFill(0x990000);
circle.graphics.drawCircle(50, 50, 50);
circle.graphics.endFill();
this.rawChildren.addChild(circle); // The quick and dirty method
/* OR YOU CAN DO THIS
var uic:UIComponent = new UIComponent();
uic.addChild(circle);
addChild(uic);
*/
event (sprite)
circle.addEventListener(MouseEvent.CLICK, startAnimation);
}
effect(s) / fade
private function fadeCircle(event:Event):void{
circle.alpha -= .05;
if (circle.alpha <= 0){
circle.removeEventListener(Event.ENTER_FRAME, fadeCircle);
}
}
animation (enter frame event(s))
private function startAnimation(event:MouseEvent):void{
circle.addEventListener(Event.ENTER_FRAME, fadeCircle);
}
]]>
</mx:Script>
</mx:Application>
(C) Æliens
27/08/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.