Question

I need to call a MovieClip that gets added from the library but I get this error:

1120: Access of undefined property light.

This is my code:

var btn:Btnselect;

btn = new Btnselect();
con.addChild(btn);
btn.name = "light" 

light.box.visible=false

Why is it undefined?

Was it helpful?

Solution

You are trying to access the movieClip like you would in the Flash IDE, where you set the name property in the properties panel and that's how you access it in AS3

However, when instantiating movieClips in AS3 (meaning, you didn't drag them from the Library to the Stage) the variable is set differently.

Here, you should be referencing "btn" not "light"

btn.box.visible = false;

because that's what you called your variable

OTHER TIPS

 Access of undefined property light.

Means that light, has a null reference, and you're trying to access it. Make sure that the variable light has been initialized or it has a reference to movie clip in the stage.

I think you should use the getChildByName method, for example

getChildByName("light").box.visible = false;

instead of :light.box.visible=false

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top