Reputation: 41
How can i access a movie clip variable from its parent? I have done tried several different ways but still failed.
Upvotes: 1
Views: 3141
Reputation:
MovieClip is a dynamic object so if you're setting a property dynamically on a movieclip or even if you want to access a builtin property or method you simply do so by directly referencing the child from the parent. Like so:
var myMovie:MovieClip = this.myChildMovie;
trace(myMovie.myProperty);
myMovie.myProperty = 7;
trace(myMovie.myProperty);
Basically in AS3 we have a proper display list, where we access children and parents through specific methods used to traverse the display list. In as2, basically new display objects become a dynamic property of their parent. So you just access them directly as a property. Note however that AS2 and AS1 have big issues with scope. Using the term "this" is subject to change depending on where you are using it. It is a context-sensitive term. Also scope can become easily lost/confused, especially in AS1. For example if you enter a function attached as a property to a clip, in the top level of that function, saying "this" will reference the function object (I believe, it's been a LONG time since as1/2 days). However, if you were to create lets say a LoadVars object inside that function, and enter the callback method of that LoadVars object, the scope changes again and thus the context of "this". I know that's probably pretty damn confusing, but you'll see as you mull it over. I advise learning AS3, you'll hate it at first but then wonder how you ever got along without it.
Anyway so short version of the lesson: ensure that when you are trying to reference this child, that you are doing it in the proper scope. If you are very new to flash all together, check out this website:
The AS2 tutorials are a few pages back but, that website should have everything you need to get you firmly on your feet with flash.
Upvotes: 1
Reputation: 41
If you are just looking to access a movieclip that exists on the stage, give it an instance name in the property panel, then you can access the variable with myMovieclip.variable.
If you are programming with as2, then check out http://www.kirupa.com/developer/oop2/AS2OOPindex.htm
Upvotes: 0