Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

using addEventListener for Enter and Exit frame

Participant ,
Mar 12, 2013 Mar 12, 2013
hi , sometimes i want to set some function in specific frame in start and exit this frame
for example i have Flv player in frame 20 , i have background sound ( mp3 player ) so i want when swf goes to this frame my sound goes Off and when Exit from it and go to another frames the sound played again ...
i put these script in frame 20 :
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");
}
but after test movie i see I started and will Exit runs Repeatly without stoping !!
Notice : first i put my sndChannel = soundClip.play; and sndChannel = soundClip.stop;  but my music runs over and over and finally my system Hanged and need to Restart so i use trace to see

so whats a problem ?  thanks for spending time and help me

TOPICS
ActionScript
11.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 12, 2013 Mar 12, 2013

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

...
Translate
Community Expert ,
Mar 12, 2013 Mar 12, 2013

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();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 12, 2013 Mar 12, 2013

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 ?!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 12, 2013 Mar 12, 2013

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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 12, 2013 Mar 12, 2013

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 ?


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 12, 2013 Mar 12, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 12, 2013 Mar 12, 2013

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 ...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 12, 2013 Mar 12, 2013

after exiting which frame?

and what causes the playhead to exit that frame?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 13, 2013 Mar 13, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2013 Mar 13, 2013

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 13, 2013 Mar 13, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2013 Mar 13, 2013

// in frame 1:

function f():void{

trace("function f is executing when the playhead is in frame:", this.currentFrame);

}

// in frame 2:

f();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 14, 2013 Mar 14, 2013

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 !!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2013 Mar 14, 2013

because your object was added before your code executed.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 14, 2013 Mar 14, 2013

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 ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2013 Mar 14, 2013

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().

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 14, 2013 Mar 14, 2013

thank you so much , now i have all thing needed by your Help

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2013 Mar 14, 2013
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines