PDA

View Full Version : Trouble with MovieClip linkage and inheritance



wmarcello
June 17th, 2009, 01:29 PM
I'll try to explain my problem as clearly as possible. I have a MovieClip on stage (and inside it are two more MovieClips name mc1 and mc2). In the Library I've set the linkage base class of this MovieClip to point to a custom class I wrote. Let's call it ClassA:



package myclass
{
import flash.display.MovieClip

//properties
private var _mc1:MovieClip;
private var _mc2:MovieClip;

public class ClassA extends MovieClip
{
//constructor
public function ClassA()
{
//mc1 and mc2 are MovieClips inside my base clip
//that i want to store as private variables
_mc1 = mc1;
_mc2 = mc2;
}
}
}
Now, this actually works fine with no errors, and I am able to access mc1 and mc2 just fine within the class.

My problem comes when instead of making the base class ClassA, I actually make the base class ClassB which extends ClassA:



package myclass
{
public class ClassB extends ClassA
{
//constructor
public function ClassB()
{
super();
}
}
}
Once I do that and test the movie, I get the following errors:
1120: Access of undefined property mc1
1120: Access of undefined property mc2

What am I doing wrong? Even if I go back into ClassA and set the private variables as protected, I am still getting the same errors.

wmarcello
June 17th, 2009, 01:42 PM
Aha! I think I figured it out. In the constructor of parent class ClassA, instead of accessing the MovieClips as:


public function ClassA()
{
//mc1 and mc2 are MovieClips inside my base clip
//that i want to store as private variables
_mc1 = mc1;
_mc2 = mc2;
}

I have to do it like this:


public function ClassA()
{
//mc1 and mc2 are MovieClips inside my base clip
//that i want to store as private variables
_mc1 = getChildByName("mc1") as MovieClip;
_mc2 = getChildByName("mc2") as MovieClip;
}