Skip to main content
asidfree
Known Participant
August 2, 2006
Answered

Field Variable trouble

Hello,

Overview: I am having a confusing time figuring out what's going on with the scope in a project I'm working on. I mocked up a version of what I'm attempting, and have attached all the code (as follows). I want to access/modify a var that resides on a movieclip's timeline.

Problem: A movieclip (called test) resides in the first frame of the main timeline. Inside test on it's first frame it declares a var called testing. From the main timeline I ask what the value of testing is, and it returns undefined.

Attempted Resolution: I have programmed in Java, and it has what they call accessor and mutator methods. I tried creating accessor/mutator functions in the movieclip, but this didn't change the error message. I also thought that it might be an issue with the ver of AS that I am using. I have MX 2004 (v7.0) and I checked the livedocs to look into seeing if I was on track. As far as I can tell I am.

Thank you for the help,

Here's the code:
This topic is closed to new replies. Start a new post to keep the conversation going.
kglad
kgladCorrect answer
Community Expert
August 2, 2006
you are encountering a timing issue. the code on the first frame of your main timeline executes before the code in the first frame of movieclips that are attached to that main timeline first frame.

so, if you want to access variables on the first frame of movieclip you must wait until those variables are defined either by waiting until some timeline advances or initiating a loop that checks if the variables are defined.

3 replies

kglad
Community Expert
Community Expert
August 2, 2006
you're welcome.
Translate
kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
August 2, 2006
you are encountering a timing issue. the code on the first frame of your main timeline executes before the code in the first frame of movieclips that are attached to that main timeline first frame.

so, if you want to access variables on the first frame of movieclip you must wait until those variables are defined either by waiting until some timeline advances or initiating a loop that checks if the variables are defined.
Translate
asidfree
asidfreeAuthor
Known Participant
August 2, 2006
Thanks, that was the problem. I added an onload method and it works fine now. I don't know why I didn't think about that.

Much appreciated.
Translate