Skip to main content
September 26, 2013
Answered

Add event listeners in a loop?

  • September 26, 2013
  • 1 reply
  • 634 views

Hi

If I have a movieclip I instantiated, called _aBet, and within that clip it has child clips named A, B, C etc

and I have an array...

aBetARR = new Array("A","B","C","D","E"... etc

How, in a loop, do you add an event listener for each of the child clips? Is it possible?

for( var i:int=0; i<aBetARR.length; i++ ) {

     _abet.[aBetARR].addEventListener(MouseEvent.CLICK, hE);

}

I've done this elsewhere in the project where I reference the actual child clips of an MC called _help in an array...

helpARR = new Array( _help.needAccount, _help.register, ...etc

for( var i:int=0; i<helpARR.length; i++ ) { helpARR.addEventListener(MouseEvent.CLICK, helpFunc); }

But is it possible to do the same using a string as a part of the reference?

Thanks guys

This topic has been closed for replies.
Correct answer Ned Murphy

Do not use a dot before the brackets...

_abet[aBetARR].addEventListener(MouseEvent.CLICK, hE);

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
September 26, 2013

Do not use a dot before the brackets...

_abet[aBetARR].addEventListener(MouseEvent.CLICK, hE);

September 26, 2013

One little dot.

Thanks Ned!!!

Ned Murphy
Legend
September 26, 2013

You're welcome