topical media & game development

talk show tell print

#graphic-flex-image-effects-06-Flex-ImageFlip.ax

#graphic-flex-image-effects-06-Flex-ImageFlip.ax [swf] [flash] flex


  package {
  
          import flash.display.Sprite;
          import flash.events.Event;
          
          [SWF(width=800, height=800, backgroundColor=0x000000)]
  
          
Rotates an image about its y axis in a continuous animation.

  
          public class @ax-graphic-flex-image-effects-06-Flex-ImageFlip extends graphic_flex_image_effects_06_Flex_AbstractImageLoader {
  
                  private var _imageHolder:Sprite;
  
                  
Constructor. Passes path of image to load to super class.

  
                  public function @ax-graphic-flex-image-effects-06-Flex-ImageFlip() {
                          super("graphic-flex-image-effects-06-assets/butterflies.jpg");
                  }
  
                  
Method that is called once image loads in super class. This nests the loaded image within another sprite to make center rotation easier, then sets up a listener for the ENTER_FRAME event to handle the animation.

  
                  override protected function runPostImageLoad():void {
                          _imageHolder = new Sprite();
                          _imageHolder.x = stage.stageWidth/2;
                          _imageHolder.y = stage.stageHeight/2;
                          // loaded bitmap is offset within image holder
                          // so that it is centered on the image holder's registration point
                          _loadedBitmap.x = -_loadedBitmap.width/2;
                          _loadedBitmap.y = -_loadedBitmap.height/2;
                          _imageHolder.addChild(_loadedBitmap);
                          addChild(_imageHolder);
                          addEventListener(Event.ENTER_FRAME, onSpriteEnterFrame);
                  }
  
                  
Handler for ENTER_FRAME. Performs the rotation animation.
parameter: event Event dispatched by this sprite.

  
                  private function onSpriteEnterFrame(event:Event):void {
                          _imageHolder.rotationY += 1;
                  }
  
          }
  
  }
  


(C) Æliens 04/09/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.