PDA

View Full Version : Libary item's children are null in the constructor



IQAndreas
November 24th, 2009, 11:16 AM
I have a class tied to a library item, but no matter what I do, if I access any of the children (added via the stage in the Flash IDE) in the constructor of the class, they always return null and give me #1009 errors.

I could work around it, but it would turn out quite ugly. Any solutions?

micken
November 24th, 2009, 11:19 AM
ADDED_TO_STAGE listener?

rkuk
November 24th, 2009, 11:35 AM
you have to put all the children on the first frame of the item and give each a instance name matching the class property, then you can access them in constructor.

but i think the most graceful way to do this is : bind each child to a class and create instances in the createChildren method of the item class

IQAndreas
November 29th, 2009, 05:20 AM
[smacks head]

Turns out I was using a SimpleButton, but I didn't think there was any difference at all.

Which leads me to a different problem, it is impossible to access the children of a SimpleButton. Let's say the child has an instance name of "nameTF". If you try to set:
simpleButton1.nameTF.text = "Andreas";
You get #1009 errors that "nameTF" is null.

I thought, "perhaps this has to do with that SimpleButton is really 4 different sprites, "upState", "downState", "overState", and "hitTestState", so, let's try accessing the child like this:
simpleButton1.upState.nameTF.text = "Andreas";
Nope, then you get another error, property not found.

Now you start getting really annoyed, so you try these two:
simpleButton1.["nameTF"].text = "Andreas";
simpleButton1.getChildByName("nameTF").text = "Andreas";

In fact, SimpleButton doesn't even have a getChildByName() or even addChild() function. Then what's the use of giving instance names to children you add via the IDE? There is no way of accessing those children anyway.

So you try again, one last time, (via an external AS file)
private var nameTF:TextField;
But then you get a "duplicate variable definition" error, meaning the IDE automatically creates this new property at compile time. However, why does it even add this new property if the value will always and forever be null?

Or am I the only one getting these results?


I don't think I want to do freelance work anymore if I have to keep using the IDE... :|
It's only getting worse and worse for me.