This content has been marked as final.
Show 9 replies
-
1. Re: managing various event listeners in multi-frame movie
kglad Sep 11, 2008 10:48 PM (in response to sneakyimp)before adding the enterframe listener, check if it already exists and, if so, remove it. -
2. Re: managing various event listeners in multi-frame movie
sneakyimp Sep 12, 2008 2:36 PM (in response to kglad)I have tried using hasEventListener to check for an existing ENTER_FRAME function before adding the event listener again but it never seems to notice that there is an existing enterframe function running. Furthermore, when I leave the frame, the enterframe function (which is attached to a particular movie clip on frame 2) continues to run even though that movie clip doesn't exist on any other frame in the flash movie.
The first frame in my movie just has a button that takes the movie to frame 2. frame 2 has a movie clip (myMovie) and a button (btnFrame1) which goes back to frame 1. It also has the attached actionscript.
I start the movie.
I click 'goto frame 2'
the enterframe listener is added and starts to output trace statements of the current frame of myMovie (e.g., 1-2-3).
i click 'goto frame 1' on the main movie
although i am looking at frame 1 of my main movie which has no instance of myMovie, the enterframe function keeps tracing the current frame--interestingly, the frame of myMovie does not advance...it stays on 1, 2, or 3 and announces that frame over and over again.
Repeating the visit to frame 1 and frame2 over and over again results in more listeners being added over and over again.
I have uploaded a sample FLA here:
http://jaith.net/questions/listenerExample.zip
I hope that you might help me determine how to remove the listener upon exiting this frame. I don't want that enterframe function running (and referring to movieclips that don't exist) when I exit the frame where it is relevant. I'm wondering if I should try adding the event listener to the root movie instead. -
3. Re: managing various event listeners in multi-frame movie
kglad Sep 12, 2008 3:43 PM (in response to sneakyimp)whenever you exit the main timeline's frame 2, you're removing myMovie from the display list. but it still exists and its listener still exists.
every time you enter the main timeline's frame 2, you're creating another instance of myMovie and another listener, IN ADDITION, to the one your previously created. and this occurs before your code executes because myMovie is on-stage.
so, if you go back and forth between frames 1 and 2, you should notice more frequent enterframe events executing as more and more movieclips have enterframe events calling your listener function.
because you're using a movieclip created in the authoring environment, you'll need to remove the listener and null myMovie before re-entering the frame that contains it.
i understand you have many frames that will need to null and remove that listener so add a function that does that and call the function from every frame where that's needed.
and hope that flash adds an exitframe event in the future.
-
4. Re: managing various event listeners in multi-frame movie
sneakyimp Sep 15, 2008 3:14 PM (in response to kglad)quote:
Originally posted by: kglad
so, if you go back and forth between frames 1 and 2, you should notice more frequent enterframe events executing as more and more movieclips have enterframe events calling your listener function.
because you're using a movieclip created in the authoring environment, you'll need to remove the listener and null myMovie before re-entering the frame that contains it.
As far as I can tell, that is indeed the behavior I see. Unfortunately, I don't know how to reference this movie that I've placed on the timeline from another frame. Any reference to myMovie from a frame where it doesn't exist is going to cause an error, right? Also, what do you mean by 'null myMovie' ? myMovie is not a var I have defined but rather a reference to a movie placed on the timeline. -
5. Re: managing various event listeners in multi-frame movie
kglad Sep 15, 2008 5:24 PM (in response to sneakyimp)no, you're incorrect. after you enter frame 2, myMovie exists. go to frame 1 and check for myMovie and you'll find it exists. you're just removing it from the display list.
this is different behavior in as3 from as2. when something was removed from the stage, it was gone and it didn't exist. -
6. Re: managing various event listeners in multi-frame movie
sneakyimp Sep 15, 2008 5:45 PM (in response to kglad)The actionscript compiler doesn't want to let me refer to myMovie in frame 1. I've tried a few things...see the attached code. All references to myMovie in frame 1 cause compiler errors, but the movie still seems to run. Is there some trick I'm missing to avoid those errors?
Also, I cannot call removeChild on myMovie from this first frame. I get an error (see attached code).
-
7. Re: managing various event listeners in multi-frame movie
kglad Sep 15, 2008 11:20 PM (in response to sneakyimp)myMovie exists but it's not in your display list so you can't remove it from its parent.
and if that code executes before you go to frame 2, you'll get all kinds of compiler errors. you can't reference myMovie until you've returned from frame 2. -
8. Re: managing various event listeners in multi-frame movie
sneakyimp Sep 16, 2008 11:12 AM (in response to kglad)Thanks for your guidance on this. You have been a tremendous help. -
9. Re: managing various event listeners in multi-frame movie
kglad Sep 16, 2008 12:38 PM (in response to sneakyimp)you're welcome.



