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 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 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. * * @param event Event dispatched by this sprite. */ private function onSpriteEnterFrame(event:Event):void { _imageHolder.rotationY += 1; } } }