attachMovie and retrieving variables within MovieClip
Hi All,
I'm having a slight problem I'm hoping someone has the answer to.
In one frame I'm attaching a MovieClip to the stage:
_root.attachMovie("Button0004", "newbutton",525);
trace("textfieldx is equal to "+_root.newbutton.textfieldx);
The trace doesn't return a value for _root.newbutton.textfieldx
But when I put the trace on a button and press it afterwards, it returns the correct value.
textfieldx is defined within the MovieClip "Button0004". I would think I would be able to access the value textfieldx as soon as I attach the movie.
Any thoughts on why it's not working directly after the movie is attached?
After putting a trace in the attached MovieClip, I'm noticing that the MovieClip is getting attached after the trace on the root level.
To make it more clear - on a button I placed the following script:
on (release) {
_root.attachMovie("ButtonTest", "newbutton",528);
trace("textfieldx is equal to "+_level0.newbutton.textfieldx);
}
Then in the MovieClip "ButtonTest" I also placed a trace in the first frame:
trace("ButtonTest textfieldx = "+textfieldx + " " + this);
The trace in the attached MovieClip appears after the trace on the button I'm pressing.
That's why the variable doesn't contain any values.
So now the question is how can I work around this?
I got to thinking about this, and you cannot target dynamic textfields inside button symbols. Now, there is a work around, which involves a little leg work. Basically you need to seperate the textfield from the button. I made a fla to show you how I got around it. I'm sure there are other ways of approaching this, but this is how I do it.
I only put in url's for 3 buttons if you test this and change the number of buttons built, but you could add more if you wanted to.