开发者

I want my MovieClip to play from frame 5 to frame 30 and then stop. How?

I want my MovieClip to play from frame 5 开发者_如何学运维to frame 30 and then stop. How can I do this?


function playSegment(target:MovieClip, begin:int, end:int):void
{
    target.gotoAndPlay(begin);
    target.addEventListener(
        Event.ENTER_FRAME,
        function(e:Event):void
        {
            if(target.currentFrame == end)
            {
                target.stop();
                target.removeEventListener(Event.ENTER_FRAME, arguments.callee);
            }
        }
    );
}

Then do:

playSegment(your_movieclip, 5, 30);

Or if you have a base class/class set up for your MovieClip then you can of course do:

public function playSegment(begin:int, end:int):void
{
    gotoAndPlay(begin);
    addEventListener(
        Event.ENTER_FRAME,
        function(e:Event):void
        {
            if(currentFrame == end)
            {
                stop();
                removeEventListener(Event.ENTER_FRAME, arguments.callee);
            }
        }
    );
}

Then:

my_movieclip.playSegment(5, 30);


If you want to do it with code, try this:

myMovieClip.addEventListener(Event.ENTER_FRAME, onEnter);
myMovieClip.gotoAndPlay(5);

private function onEnter(e:Event) : void {
    if(myMovieClip.currentFrame == 30) {
        myMovieClip.stop();
        myMovieClip.removeEventListener(Event.ENTER_FRAME, onEnter);
    }
}


You can use addFrameScript method too.

protected function addMovieClip():void{
    mc = new MovieClip();
    addChild(mc);
    mc.gotoAndPlay(5);
    mc.addFrameScript(30, frameFunction);
}

protected function frameFunction():void
{
    mc.stop();
    //clear the code by writing null script to target frame.
    mc.addFrameScript(30, null);
}

Hope this helps.


on frame 1 add the actionscript type: gotoAndPlay(5); on frame 30 add stop();


first frame: gotAndPlay(5) and in frame 30 a simple stop()?

Edit: This is actually more than basic Flash coding. So you perhaps do not know how to add script to a frame? See the Flash docs for "Adding interaction".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜