actionscript-3flashmovieclipprezi

Simulating a MovieClip in pure as3


I am looking for a way to make a Flash movie clip (animation, like the ones created with Flash Pro CS), but purely in as3 - so I can import them into Prezi.

I have done a lot of as3 programming in Flash Builder with Flex projects and I have no background in how MovieClips work.

What I have already tried is extending a MovieClip class and trying to base the animation on Timers, this failed so I tried with ENTER_FRAME event (because flash animations are based on frames - so I thought...). But all this fails, only graphics drawn in the constructor are displayed - no animation happens. (As I wrote in the first paragraph I am testing this importing the swf into Prezi, opening it in a browser works as expected)

Is there any way to do it? Like listening to specific events?


Solution

  • Funny thing happened. I wanted to show you a sample code I was trying out (I already tried Sprite with ENTER_FRAME), that was not working. By accident I found a solution. It looks like you need to draw something in the first frame, or else the other frames won't work (in Prezi at least).

    So here is the working code:

        public class PreziTest extends Sprite{
            private var radius:uint = 10;
    
            public function PreziTest(){
                addEventListener(Event.ENTER_FRAME, onEnterFrame);
    
                onEnterFrame(null); // WITHOUT THIS IT WON'T WORK - YOU NEED TO DRAW SOMTHING IN THE FIRST FRAME
            }
    
            private function onEnterFrame(event:Event):void{
                radius += 10;
    
                if(radius > 200)
                    radius = 10;
    
                graphics.clear();
                graphics.beginFill(0xff0000);
                graphics.drawCircle(radius, radius, radius);
            }
        }
    

    Thanks for all your help!