开发者

Embed SWC cannot access textfield

开发者 https://www.devze.com 2023-04-03 20:51 出处:网络
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开发者_运维技

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消