0

I was very familiar with AS2 and am just getting familiarized with AS3.

I have a movieclip that serves as a button. On hover, Flash plays the second frame of that movieclip. My question is how can I create a reusable function that can play the second frame of any movie clip that it gets applied to without having to specify the movieclip each time. The code below obviously can only be applied to "btn_next". I wrongfully assumed that changing 'btn_next.gotoAndPlay(2)' to 'this.gotoAndPlay(2)' would work but the 'this' doesn't target the button calling the function.

btn_next.addEventListener(MouseEvent.ROLL_OVER mouseOverHandler)

function mouseOverHandler (event: MouseEvent):void {
    btn_next.gotoAndPlay(2);
}

Any help would be most appreciated. Thanks in advance!

D

user2325396
  • 105
  • 2
  • 12
  • `event.target.gotoAndPlay(2)` if memory serves. – sberry May 23 '13 at 23:20
  • brilliant! thank you. By any chance could you share with me how to pass a parameter through a function similar to the one above. It can be a basic trace example. Thank you again in advance :) – user2325396 May 23 '13 at 23:29
  • I am not sure what you mean. – sberry May 23 '13 at 23:36
  • My apologies...I should have been clearer. What is the proper way to pass a parameter through mouseOverHandler? For example, say that I'd like to pass a string through the function so that it shows up in a trace. A may have 4 buttons that would each shoot different words through the function so that they'd show up in the trace. I hope that's clearer. Thanks! – user2325396 May 23 '13 at 23:45
  • Could you make that into a new question please. Keep the forum organized and easy to browse. Thanks – RST May 24 '13 at 01:08
  • 1
    @user2325396 Read [this question and answer](http://stackoverflow.com/questions/6406957/how-to-pass-arguments-into-event-listener-function-in-flex-actionscript/6407128#6407128) before you go on to ask that. – Marty May 24 '13 at 01:19

1 Answers1

0

to make the event handler function works with any movieclip: event.target.gotoAndPlay(2);

To pass parameter, you cannot do it directly with MouseEvent. But you can do a switch statement on the event.target or event.target.name and depending on that you do something:

switch (event.target)
{
    case mc1:
        trace("first mc");
        break;
        ...etc
}
Mahmoud Badri
  • 1,256
  • 14
  • 24