AS3 Add Event Listener in For Each
        Posted  
        
            by 
                Vinzcent
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Vinzcent
        
        
        
        Published on 2011-01-02T18:18:04Z
        Indexed on 
            2011/01/02
            18:54 UTC
        
        
        Read the original article
        Hit count: 255
        
flash
|actionscript-3
Hi,
I would like to add an eventlistener to all the elements I create in a for each loop. But apperently the eventlistener only works with the latest created element.
How do I add an Event Listener to every element created in the for each loop?
This is my code:
        for each(var showCase:ShowCaseItem in _bllShowCase.arrShowCase)
        {
            var listItem:ListItemShowCase = new ListItemShowCase(showCase);
            listItem.y = yPos;
            listItem.addEventListener("ITEMDELETED", refreshShowCaseItems);
            this.addChild(listItem);
            yPos += 20;
        }
I hope you understand my question.
Thanks, Vincent
© Stack Overflow or respective owner