Copy link to clipboard
Copied
addEventListener(Event.ENTER_FRAME,enterfunc);
function enterfunc(e:Event):void {
trace("I started");
}
addEventListener(Event.EXIT_FRAME,exitfunc);
function exitfunc(e:Event):void {
trace("will Exit");
}
so whats a problem ? thanks for spending time and help me
because their names are misleading. Event.EXIT_FRAME doesn't execute once when the playhead exits a frame. it executes repeatedly.
likewise, Event.ENTER_FRAME doesn't execute once when the playhead enters a frame. it executes repeatedly.
you can execute a function when the playhead enters a a frame by adding a function call to the frame:
f(); // attached to a frame will call the function f when the playhead enters this frame. and there are other ways to do this.
you can execute a function when
...Copy link to clipboard
Copied
those probably aren't going to do what you want but, if you wanted each to execute once, remove the event listener.
but again, i doubt that will do what you want.
you probaby want to use an Event.ADDED_TO_STAGE listener and Event.REMOVED_FROM_STAGE listener appied to your flvplayback component to trigger your background music to stop and play:
flv_pb.addEventListener(Event.ADDED_TO_STAGE, addedF);
flv_pb.addEventListener(Event.REMOVED_FROM_STAGE, removedF);
function addedF(e:Event):void{
sndChannel.stop();
}
function removedF(e:Event):void{
sndChannel=soundClip.play();
}
Copy link to clipboard
Copied
thanks Kglad .
i will test your tips tomorrow and as i know you i know it will help me as always ...
but just for know can you tell me why addEventListener and
Event.EXIT_FRAME or
Event.ENTER_FRAME
runs repeatly and what script i must use if i want to add function in start or Exit frame at Once ?
cause maybe i want to use this in frames that have not Flv player or any Movieclip with instance name ...
am i forced to put some movieclip in frame and then use Event.ADDED_TO_STAGE and Event.REMOVED_FROM_STAGE script to them always ?!
Copy link to clipboard
Copied
because their names are misleading. Event.EXIT_FRAME doesn't execute once when the playhead exits a frame. it executes repeatedly.
likewise, Event.ENTER_FRAME doesn't execute once when the playhead enters a frame. it executes repeatedly.
you can execute a function when the playhead enters a a frame by adding a function call to the frame:
f(); // attached to a frame will call the function f when the playhead enters this frame. and there are other ways to do this.
you can execute a function when a playhead exists a frame by invalidating the stage and using a render event when a goto is executed:
stage.invalidate();
this.addEventListener(Event.RENDER,exitingF);
this.gotoAndPlay('whatever');
function exitingF(e:Event):void{
// this code executes when this frame is exited and 'whatever' is rendered (=displayed);
}
Copy link to clipboard
Copied
thanks Dear Kglad for spending Time for me
your script works well in Enter Frame
but how i must use this for Exit Frame ? am i must use removeEventListener for this ?
Copy link to clipboard
Copied
depending on exactly what you want and what's going on in the swf there are better and worse ways to detect what you want.
Copy link to clipboard
Copied
sorry , i never wants to bother you , after your Help and Guide i search around Web and maybe for my weak English i cant get what i want ...
i dont need any compilcated fuction or code , i just want to set a simple function ( sound pause ) or Goto Run , rigt after Exit frame ...
Copy link to clipboard
Copied
after exiting which frame?
and what causes the playhead to exit that frame?
Copy link to clipboard
Copied
After Exiting Current Frame
for example i want to :
when Enter Frame No.2 or Frame with Lable "two"
some function run
and when i exit this frame some another Function Runs
i have Stop(); script in frame 2 and i want to use exit script to run function cause i want this script runs with every menus and categories that goes to another Frames
Copy link to clipboard
Copied
again, for your enter frame question:
you can execute a function when the playhead enters a a frame by adding a function call to the frame:
f(); // attached to a frame will call the function f when the playhead enters this frame. and there are other ways to do this.
and again, for your exit frame question:
and what causes the playhead to exit that frame?
Copy link to clipboard
Copied
so sorry i cant get your Get your point about : adding a function call to the frame
how can i f(); // attached to a frame will call the function f when the playhead enters this frame ??
can you explain it simple or with a example script ?
about causes the playhead to exit that frame well there is not only one button to cause exit frame , i have about 5 menus ( about , contact , products , ... ) and some other buttons and on click on every of them the swf goes to specific Frame and , so i cant set function on every of them ...
For example my frame No2 .
have some Sound Or MOvies and i want when enter this frame Background Sounds Goes off and when i exit This frame ( it may happends with every Menu or Buttons and not only one ) the Background sound Play again
Copy link to clipboard
Copied
// in frame 1:
function f():void{
trace("function f is executing when the playhead is in frame:", this.currentFrame);
}
// in frame 2:
f();
Copy link to clipboard
Copied
kglad wrote:
// in frame 1:
function f():void{
trace("function f is executing when the playhead is in frame:", this.currentFrame);
}
// in frame 2:
f();
This works well For Excute Function on entering Frame Once !! thanks ...
but Only 1 More Question :
as You told me in your No.2 Replay :
I try to add some movieclip with instance name Or FLv playback with instance name and then Try to use this codes :
mymc.addEventListener(Event.ADDED_TO_STAGE, addedF);
function addedF(e:Event):void{
trace("I Start");
}
mymc.addEventListener(Event.REMOVED_FROM_STAGE, removedF);
function removedF(e:Event):void{
trace("I exit");
}
why The removedF function Works well and the addedF function not work ?!? in fact nothing Happend on Enter This Frame but on exit i see my I exit Trace !!
Copy link to clipboard
Copied
because your object was added before your code executed.
Copy link to clipboard
Copied
So what can I do about this ??
as i test i cant move
mymc.addEventListener(Event.ADDED_TO_STAGE, addedF);
function addedF(e:Event):void{
trace("I Start");
}
to Previous Frames cause the error Cannot access a property or method of a null object reference. comes !! and sort of Layers not help too
it seems ADDED_TO_STAGE is not Opposite of Event.REMOVED_FROM_STAGE !! or in this situation i must use another Script ?!?
and I need some Another Event Script to Realize my object and run a function , isn't it ?
Copy link to clipboard
Copied
it doesn't make any sense to use that code on a timeline. that event is used in class files to guarantee access to the display list.
attached to that frame, just call addedF().
Copy link to clipboard
Copied
thank you so much , now i have all thing needed by your Help
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now