I might be missing something. I thought this would be a common question but extensive search on the web over a few days didn't turn up the answer I need. I am hoping to make a self-contained movie clip that would function wherever it is placed. However, it seems difficult to access instances defined in the movie clip from within a class that extends the movie clip.
Although I am coding in Flash Actionscript 2 (AS2), I wonder if the same issue exists for AS3.
In the following scenario, how do you access the instance "circle"?
A movie clip on the main timeline has an instance name "square". A class Square defined in Square.as extends this movie clip. Inside the movie clip, another movie clip is placed on the first frame, with instance name "circle". There is also a varialbe declared on the first frame var myName:String = "my name"
. The following code doesn't compile:
class Square extends MovieClip {
function Square() {
trace("Square.constructor, circle: " + circle);
trace(" --- myName: " + myName);
}
}
Compiler errors: There is no property with name 'circle'.
(same for myName).
Adding this.
in the reference doesn't help. Apparently, the compiler is looking for the varialbles in the class definition.
Using _level0.square.circle
works, but that requires the class to know its own instance path. While _level0.square.myName
doesn't produce compiler errors, it gives a value of undefined
.
Referencing these variables in methods other than the constructor causes the same compiler errors.
Thanks much for your help.