Search code examples
actionscript-3apache-flexfor-loopaddeventlistenerflashbuilder4

dynamically create, add and addEventListener items in flash builder 4.6


I am using Adobe Flash Builder 4.6 and trying to create, add and addEventListener to objects that i created dynamically, in as2 i was doing it by:

for(i=0;i<10;i++){
    abc[i]doSomeThing;
}

How it is in actionScript 3? I searched it much and found nothing, so any help would be greatly appreciated.


Solution

  • you have to use AS3.0 in flash

    for(var i:int=0;i<10;i++){
    
      abc[i].addEventListener(MouseEvent.CLICK,doSomeThing);
    
    }
    
     function doSomeThing(event:MouseEvent):void
    {
       switch(event.target)
    {
        case abc[0]:
        //statements for object 1;
        break;
        case abc[1]:
        //statements for object 2;
        break;
        '
        '
        '
        '
        '
        '
    }
    }