How do I pass an array through a function call?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • luke noob
    New Member
    • Aug 2009
    • 69

    How do I pass an array through a function call?

    my code come up with an error #1010 undefined property.

    Code:
    import flash.events.MouseEvent;
    import flash.display.MovieClip;
    
    var buttons:Array = new Array();
    
    createButtons([ square1, square2, square3, square4, square5 ]);
    
    function createButtons(buttons){
    
    for (var i:int = 0; i<=buttons.length;i++){
    
    buttons[i].addEventListener(MouseEvent.CLICK, clickButton);
    
    
    
    }
    
    }
    function clickButton(event:MouseEvent){
    
     var square:MovieClip = MovieClip(event.currentTarget);
    
    trace(square.name);
    
    }
  • Anas Mosaad
    New Member
    • Jan 2013
    • 185

    #2
    I believe you need to quote the string in line 6.
    Code:
    createButtons([ square1, square2, square3, square4, square5 ]);
    You need to change it to:
    Code:
    createButtons([ "square1", "square2", "square3", "square4", "square5" ]);
    Otherwise, you may need to define the square variables in your code.

    Comment

    Working...