退出帧后Flash AS3运行功能

时间:2013-08-21 18:32:32

标签: actionscript-3 flash flash-cs5

当我离开一个特定的框架时,我真的需要一些AS3脚本来运行某些功能。

我的理由是在退出包含FLV播放的帧后放置一些功能来停止视频并恢复我的mp3播放器声音。


我使用这个脚本,它在FLash投影机中工作得很好但是stage.invalidate();导致像Swfkit和Zinc这样的第三方应用程序制造商在尝试退出flv播放帧后没有响应。

这是我的剧本:

stage.invalidate();

mene.addEventListener(Event.RENDER,exitingF);
mene.addEventListener(Event.REMOVED_FROM_STAGE, removedF);

function exitingF(e:Event):void{

            controller.gotoAndStop(2);
            pausePosition = sndChannel.position; 
            sndChannel.stop();
            isPlaying = false;
}


function removedF(e:Event):void{
            mene.stop();
            controller.gotoAndStop(1);
            sndChannel = soundClip.play(pausePosition);
            isPlaying = true;
}

所有我需要的是另一种说法,在退出specfic帧后立即运行一些脚本(转到另一帧)

1 个答案:

答案 0 :(得分:0)

尝试使用addFrameScript()功能。

它的工作方式如下:OBJECT.addFrameScript(FRAME, CALLBACK)

这将向时间轴添加脚本,并且只要到达指定的帧,就会执行回调。

以下是我发现的一个例子:http://blog.newmovieclip.com/2007/04/30/add-a-frame-script-addframescript-dynamically-in-flash-cs3/

package com.newmovieclip{
import flash.display.MovieClip;
public class Main extends MovieClip {
public var myStar:Star;
         //constructor
public function Main() {
    //place a star on stage
    myStar = new Star();
    addChild(myStar);
    //add script to star timeline on frame 5
    myStar.addFrameScript(4,frameFunction); // (zero based)
}
private function frameFunction():void {
    trace("Executing  code for star Frame  5" );
    //delete frame script by passing null as second parameter
    myStar.addFrameScript(4,null);
        }
}
}

请记住,框架基于0,如示例

中的内联注释中所述