I have an actionscript 3 library item, "BG", that is linked to the class BGClass. BG contains a Sprite that has an instance name, "bg" and likewise BGClass has a public bg property. So the class looks like this:
public class BGCass extends Base {
public var bg:Sprite;
public function BGCass() {
bg.width = 200
}
}
Everything works fine. But if I wish to move the public bg into the Base class like this I get the error.
public class BGCass extends Base {
public function BGCass() {
bg.width = 200
}
}
public class Base extends Sprite {
public var bg:Sprite;
public function Base() {
}
}
I have tried using getter setters in Base and overriding them in BGClass and I still get the error. Is this a bug in Flash? Is there a clean solution or do I need to create some sort of proxy variable to finally get bg to Base? I know that turning off "automatically declare stage instances" in Flash will get rid of the error but I need to keep it on for the designers. Any solutions?
You have a couple of options.
Rename your "bg" variable or the "bg" stage instance to something else so that they don't match.
If you go to File > Publish Settings... > Flash tab and click the "Settings..." button next to Actionscript 3.0 you'll see an option checked off by default labelled "Automatically declare stage instances". If you disable this option, the error you're seeing will disappear, although you might see some other errors pop up as a result.
If you go with option 2, I believe that the variable will be automatically populated with a reference to the stage instance, if you leave their names the same.
Some background: When you create a library item with a base class, Flash creates a new class behind the scenes which extends the class you've chosen. By default, Flash is configured to give that class a set of member variables that match the children you've placed inside the MovieClip in the authoring environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With