FORUMS: list search recent posts

assigning event listeners with an array AS3

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Run Rodriguez
assigning event listeners with an array AS3
on Mar 17, 2009 at 9:41:00 pm

I am trying to find a workaround for assigning event listeners to multiple buttons. I realize that I can assign one event listener to a movie clip containing a group of buttons, but in this case I'd rather not go that route.

This is the long way to write my code:

nav.block1.button1.addEventListener(MouseEvent.MOUSE_OVER, rollBlock1);
nav.block1.button2.addEventListener(MouseEvent.MOUSE_OVER, rollBlock1);
nav.block1.button3.addEventListener(MouseEvent.MOUSE_OVER, rollBlock1);
nav.block1.button4.addEventListener(MouseEvent.MOUSE_OVER, rollBlock1)

And this is my attempt at a shortcut, which is not working because I probably shouldn't be using String. Without it, I get an undefined array variable:

var block1buttons:Array = new Array();
for (var i:Number = 1; i<5; i++) {
block1buttons[i].addEventListener(MouseEvent.MOUSE_OVER, rollBlock1);

The error I get with this code is: TypeError: Error #1006: value is not a function.

Any suggestions?

Return to posts index

Mark Jeater
Re: assigning event listeners with an array AS3
on Mar 30, 2009 at 7:54:28 am

Hi Run,

After struggling for hours yesterday on a similar problem, I found an solution.

block1buttons[i] = this["nav"]["block1"]["button" + i];


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved