1
votes

i really need some AS3 Script for run some function when i leave a specfic frame.

my reason is to put some function to stop video and resume my sound of mp3 player AFTER i exit the frame that contain FLV playback .


i use this script and it`s work great in FLash projector but stage.invalidate(); cause the Third party application maker like Swfkit and Zinc Not responding after i try to exit from flv playback frame.

Here is my Script :

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;
}

all i need is some another way to say flash run some script right after exit specfic frame ( go to another frame )

1

1 Answers

0
votes

Try using the addFrameScript() function.

It works like so: OBJECT.addFrameScript(FRAME, CALLBACK)

This will add a script to a timeline and the callback will be executed whenever the specified frame is reached.

Here's an example I found: 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);
        }
}
}

Remember that frames are 0 based as mentioned in the inline comment from the example