PDA

View Full Version : AS 3 Question - Capturing Menu Click/How to call back from class event listener


mwiley63
08-09-2007, 02:18 AM
Hello,

I have recently started learning actionscript 3, and I think this is just some concept I am not understanding.

I found a class for a menu that I am using, basically I want to attach a Movie Clip to the stage when a menu button is hit, but I am stuck on how to do this. Basically I have this in my main timeline:

import menuexample.BasicMenu;
import movieClipTest.movieClipTest;
var myMenu:BasicMenu = new BasicMenu();
myMenu.init();
myMenu.x = 50;
myMenu.y = 100;
addChild(myMenu);

var myClip:movieClipTest = new movieClipTest();
myClip.init();

// now how do I add it to the stage when a button is hit in the menu?


I have this in my BasicMenu class:

private function displayMessage(event:MouseEvent):void {

// Output the name of the clicked button.
trace(event.currentTarget.name);
}

Which traces the text (which is set to the button name) to the output window.

Can I do any kind of call back function? I know AS3 is trying to get away from this.

Thanks in advandce

mwiley63
08-09-2007, 03:50 AM
Never mind, I figured it out. I just set a click event listener and used a public variable inside of the class to get the value of the button that was pressed. I don't know why I didn't think of that before.