Friday, July 6, 2012

[Action Script] MovieClip: Next frame every interval July,2012

I'm programming a simple shooter in which enemies enter from the right and the player is at the left. This enemy is a MC with 2 frames, which I want to alternate every set number of pixels. Here is the code:
Code: package  {
       
        import flash.display.MovieClip;
        import flash.events.*;
       
        public class Enemy extends MovieClip {
               
                var OrigX:int;
               
                public function Enemy() {
                        this.gotoAndStop(1);
                        this.addEventListener(Event.ENTER_FRAME, loop);
                        OrigX = this.x;
                }
               
                function loop(event:Event) {
                        this.x -= 1;
                        if (OrigX - this.x >= 15) {
                                this.nextFrame();
                                OrigX = this.x;
                        }
                }
        }
       
}The MC doesn't change frames as it should...It only changes frames once, and that is after it is beyond the left edge of the stage.
I have also tried Code: addEventListenerinstead of Code: this.addEventListenerif that matters.
(Thanks in advance.)
MovieClip: Next frame every interval

Related Post



0 comments: