hon
hon

Reputation: 135

stop movie clip

I want to stop a movie, when it enters the last frame, i did this as below:

package{
    import flash.display.Sprite;
    import flash.display.MovieClip;
    import flash.events.Event;

    public class MeiYi extends Sprite{
        private var mainMovie:MovieClip = new MeiYiMain();  //MeiYiMain is build in the library of flash cs4

        function MeiYi():void{
            //stop at last frame
            mainMovie.addEventListener(Event.ENTER_FRAME, stopMainMovie);
            //trace(mainMovie.totalFrames);
            //mainMovie.gotoAndStop(50);
        }

        private function stopMainMovie(evt:Event):void{
            //trace(mainMovie.currentFrame);
            if (mainMovie.currentFrame == mainMovie.totalFrames){
                mainMovie.stop();  //stop
            }
        }
    }
}

but this did nothing for me, no errors or the thing that i want. What's wrong with it? thank you.

Upvotes: 0

Views: 852

Answers (2)

Shannon
Shannon

Reputation: 837

An easy solution is just to put:

stop();

In the last frame of the MovieClip (MeiYiMain). You can do this by selecting it and pressing F9 to bring up the ActionScript panel.

Also see the totalframes property in live docs for class MovieClip:

The total number of frames in the MovieClip instance.

If the movie clip contains multiple frames, the totalFrames property returns the total number of frames in all scenes in the movie clip.

This may effect it as well later on.

Upvotes: 2

Marty
Marty

Reputation: 39456

Should work fine, which is odd. Try making a class for MeiYiMain and adding the listeners within that, rather than from within MeiYi.

package
{
    import flash.display.MovieClip;
    import flash.events.Event;

    public class MeiYiMain extends MovieClip
    {
        /**
         * Constructor
         */
        public function MeiYiMain()
        {
            addEventListener(Event.ENTER_FRAME, _handle);
        }

        /**
         * Handle
         * @param e Event.ENTER_FRAME
         */
        private function _handle(e:Event):void
        {
            if(currentFrame == totalFrames)
            {
                removeEventListener(Event.ENTER_FRAME, _handle);

                trace('stopped');
                stop();
            }
        }
    }
}

Upvotes: 0

Related Questions