apprentice
06-28-2010, 03:52 PM
Could someone be so kind as to lend a hand to me with AS3? I have 5 buttons on a simple game menu where I'm trying to change the content in a dynamic textfield when mousing over any of the buttons. I've managed to populate the textfield with a single variable, but if I want to add the other buttons, do I have to create new function names for each one that target the same textfield? I guess it feels cumbersome with so many lines of code, whereas in AS2 it could be done with a few lines of code without having to specify a function name for each mouse event:
btn2.on(rollOver) {
myText = "Activity 2";
}
-----------------------------------------------------------------
AS3 code:
-----------------------------------------------------------------
var myText:TextField = new TextField();
myText.text = ""; //start out empty
myText.type = TextFieldType.DYNAMIC;
addChild(myText);
btn1.addEventListener(MouseEvent.MOUSE_OVER, btnMouseOver);
function btnMouseOver(event:MouseEvent):void {
myText.text = "Activity 1";
}
btn2.on(rollOver) {
myText = "Activity 2";
}
-----------------------------------------------------------------
AS3 code:
-----------------------------------------------------------------
var myText:TextField = new TextField();
myText.text = ""; //start out empty
myText.type = TextFieldType.DYNAMIC;
addChild(myText);
btn1.addEventListener(MouseEvent.MOUSE_OVER, btnMouseOver);
function btnMouseOver(event:MouseEvent):void {
myText.text = "Activity 1";
}