PDA

View Full Version : Why can't I access button from inside MC?



imadingo
March 1st, 2009, 07:12 PM
I am learning how to create menu systems for a game and have a few different "screens" (movieclips with buttons and such).

I am getting Undefined Property errors when I try to access a button from the class file of a screen.

Example: I have a MainMenu screen. This has its own class MainMenu.as.

Inside the library MainMenu movieclip, I have a button, instance named start_button.

But inside the MainMenu.as file, I try to do start_button.addEventListener(...) and it says undefined property.
I tried doing getChildByName("start_button"), that won't work either.

I am following a tutorial, which makes this even more frustrating.

kevin416
March 1st, 2009, 09:45 PM
Try adding the movieClip using AS3 as well.

In the MainMenu mc, you can add the button using addChild( start_button ), assuming start_button is the button variable. For example, if Start_Button was a class:


var start_button:Start_Button = new Start_Button();
addChild( start_button );
start_button.addEventListener( ... );

To help you more, I'd need to see the tutorial, your code, or both.