Hello :)
1 - creates a new class to creates your custom buttons and implement the
addEventListeners in this class (in the constructor for example)

2 - use the dynamic loop :

var down:Function = function( e:MouseEvent ):void
{
     trace( e.type + " : " + e.target ) ; // only one method and use the
target of the event to change your strategy
}

var l:Number = 100 ;

for( var i:int ; i<l ; i++)
{
    this["bt"+i].addEventListener( MouseEvent.MOUSE_DOWN ,  down ) ; // use
basic name bt1, bt2, ... it's more easy
}

EKA+ :)

2009/5/1 <zu...@zadesigns.com>

>
>
> Is there a better way to write Event Listeners for a large number of
> buttons that increment the names by 1? example:
> solution_button1.addEventListener(MouseEvent.MOUSE_DOWN, s_btn1_down);
> solution_button2.addEventListener(MouseEvent.MOUSE_DOWN, s_btn2_down);
> solution_button3.addEventListener(MouseEvent.MOUSE_DOWN, s_btn3_down);
> solution_button4.addEventListener(MouseEvent.MOUSE_DOWN, s_btn4_down);
> solution_button5.addEventListener(MouseEvent.MOUSE_DOWN, s_btn5_down);
> solution_button6.addEventListener(MouseEvent.MOUSE_DOWN, s_btn6_down);
> solution_button7.addEventListener(MouseEvent.MOUSE_DOWN, s_btn7_down);
> solution_button8.addEventListener(MouseEvent.MOUSE_DOWN, s_btn8_down);
> solution_button9.addEventListener(MouseEvent.MOUSE_DOWN, s_btn9_down);
>
>  can the above be accomplished with a for loop? what about more than one
> event over, out, down, click. can those also be automated or would I need 4
> loops for that.
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to