#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2006
    Posts
    660
    Rep Power
    32

    Creating 10 functions using for loop?


    I am trying to create functions using a for loop for my buttons' over and out listeners.

    I would like to stick to a naming convention but it does not seem to work. I am trying to create 10 buttons with function names like btnOver1, btnOver2, etc...

    Code:
    for(var i:int=0;i<=9;i++){
    	function btnOver[i](e:MouseEvent):void{
    		btn_mc[i].play();
    	};
    }
    I am getting a syntax error: expecting leftparen before leftbracket
  2. #2
  3. No Profile Picture
    Gotta get to the next screen..
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2003
    Location
    Legion of Dynamic Discord
    Posts
    6,678
    Rep Power
    3165
    Code:
    import flash.events.MouseEvent;
    
    function doButtonOver(e:MouseEvent):void
       {
          e.currentTarget.play();
       };
    
    for(var i:int = 0; i < 10; i++)
       {
          this.getChildByName("btn_mc" + i).addEventListener(MouseEvent.ROLL_OVER, this.doButtonOver);
       }
    Quis custodiet ipsos custodes?

IMN logo majestic logo threadwatch logo seochat tools logo