topical media & game development

talk show tell print

sample-flex-shape-anim.mx

sample-flex-shape-anim.mx [swf] flex


  <?xml version="1.0" encoding="utf-8"?>
  <mx:Box xmlns:mx="http://www.adobe.com/2006/mxml"
  initialize="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;
  
      public var xpos:Number = 50;
      public var ypos:Number = 50;
  
  

init(s)


      
      public function init():void{
       circle = new Sprite();
       circle.graphics.beginFill(0x990000);
       circle.graphics.drawCircle(xpos, ypos, 50);
       circle.graphics.endFill();
      
       this.rawChildren.addChild(circle);  // The quick and dirty method
        
  

alternative(s)


       /* 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:Label text="fade" />
  </mx:Box>
  


(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.