I added a SWC with movieclip assets to my flash builder project. I can access all movieclips with dot syntax but when I try to access my textfields it throws an error saying it is cannot a开发者_运维技巧ccess a property or method of a null object reference
Here is my code:
// gameMenuLevels is a main asset.
this.object = new gameMenuLevels();
This all works fine, I can go two levels deep:
var levelString:String = "level" + Utils.zeroPad(i + 1, 3);
var level:MovieClip = this.object[levelString] as MovieClip;
var bronze:MovieClip = level.bronze as MovieClip;
But when I try to get my textfield:
(bronze.getChildByName("levelNumber") as TextField)
It throws the error.
Okay with trial and error and help from this answer to another question: SWC Instance name on movieclips?
I found had to give all my child elements a linkage name (export to actionscript) and an instance name. Once that was done I could then access the child elements as a property. Hopefully this helps someone else.
精彩评论