Flash CS5 AS3 Code works no matter where it sits?

This is a general question about AS3.

I can't seem to "isolate" code.

I have a layer called AS3-Aud, where I handle the AS3 that control my project's audio files.

The first "section" of AS3 is on frames 1-29, the 2nd section is on frames 30-59.

If I write the following code (see below) and put it in the 30-59 frames section (see attached image if this isn't clear), why does it trace "Just Entered Frame 1", "Just Entered Frame 2", etc. when the playhead enters those frames? Shouldn't the code only run in the frames that has AS3 layer?

AS3 CODE=================================
addEventListener(Event.ENTER_FRAME,fx_enterFrame2);
function fx_enterFrame2(event:Event) {
      trace("Just Entered Frame " + currentFrame);
}
=========================================
screenshot
tlengnickAsked:
Who is Participating?
 
blue-genieCommented:
when you file loads, does it play through to frame 30 or is there a stop there?
if you let your file play through to frame 30 where it creates the event listener, it will keep listening for the onEnterFrame event until you explicitly stop it.
0
 
tlengnickAuthor Commented:
Got it - good to know! How do I explicitly stop it?
0
 
blue-genieCommented:
removeEventListener(Event.ENTER_FRAME,fx_enterFrame2);
0
 
tlengnickAuthor Commented:
Great - thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.