AS3. MouseEvent click in (for) loop function

164 Views Asked by At

am need here onClick one of the movieclip loop_Task.addChild(tee) trace the tee.task_id.text which one is clicked from the list for ex. this

output be like
(List Clicked : 100)
(List Clicked : 101)

or onClick passed the item data it's already clicked to new class screen

here is my code

public function resultHandlerList_items(event:SQLEvent):void
    {
        // TODO Auto-generated method stub
        var result:SQLResult = selectStmt1.getResult(); 
        var numResults:int = result.data.length; 
        for (var i:int = 0; i < numResults; i++) 
        {
            var row:Object = result.data[i]; 
            var tee:listview_mc = new listview_mc
            loop_Task.addChild(tee)
            tee.y = 270*i
            tee.task_id.text = row.Tid
            tee.task_tit.text = row.Ttitles
            tee.task_stime.text = row.Stime
            tee.task_subject.text = row.Subject
            tee.addEventListener(MouseEvent.CLICK, onClickList)
        }           
        function onClickList(e:MouseEvent):void{
        trace("List Clicked : " + e.currentTarget)
        }
 }
1

There are 1 best solutions below

0
Ibrahim Ayyad On BEST ANSWER

in the first thanks to @Organis He give me the way to fix my code and he give me info about how to talk with the compiler with exactly how to make the compiler understand your code this code the fix (e.currentTarget as listview_mc) and now this my code after fixing and i do take a public var String and pass it to other Class

    public function resultHandlerList_items(event:SQLEvent):void
        {
        // TODO Auto-generated method stub
        var result:SQLResult = selectStmt1.getResult(); 
        var numResults:int = result.data.length; 
        for (var i:int = 0; i < numResults; i++) 
        {
            var row:Object = result.data[i]; 
            var tee:listview_mc = new listview_mc
            loop_Task.addChild(tee)
            tee.y = 270*i
            tee.task_id.text = row.Tid
            tee.task_tit.text = row.Ttitles
            tee.task_stime.text = row.Stime
            tee.task_subject.text = row.Subject
            tee.addEventListener(MouseEvent.CLICK, onClickList)
        }           
        function onClickList(e:MouseEvent):void{
        trace("List Clicked : " + (e.currentTarget as listview_mc).task_id.text)
         ts_id = (e.currentTarget as listview_mc).task_id.text;
         sport._sport.Remove_Home_Sc(e);
        trace("done")        
        }
    }