0
votes

I'm new to AS, especially AS3.

Here's the problem, I created a simple mouse-over interactivity using AS2, and I want to change it to AS3.

On the stage, I have several instances of a button, instance1, instance2, …. I also have a dynamic text box with instance name "txt_box". The initial text in the box reads "Initial Text".

On mousing over each button instance, the dynamic text changes depending on the instance. Let's say, it changes to description1, description2, ….

To do that, I attached the following code to the button instances (the code below is for instance1):

on (rollOver) {
txt_box.text = "Description1.";
}
on (rollOut) {
txt_box.text = "Initial Text";
}

So simple in AS2. How can I do that in AS3?

1

1 Answers

2
votes

Assuming Btn to be an instance of a movieclip containing a textbox named txt_box, Use:

Btn.addEventListener(MouseEvent.ROLL_OVER, mouse_over);

Btn.addEventListener(MouseEvent.ROLL_OUT, mouse_out);


function mouse_over(event:MouseEvent):void {

        Btn.txt_box.text = "Description";

        }

function mouse_out(event:MouseEvent):void {

        Btn.txt_box.text = "Initial Text";

        }