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):v开发者_开发技巧oid{
//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.
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.
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();
}
}
}
}
精彩评论