开发者

Detech event target from which position of Array

I have a loop MC which will be duplicate to stage several times according to every click. Now I want to detect if the MC being click belongs to whi开发者_JS百科ch position in the array.

private function levelsBG():void {

        LIST = new MovieClip();
        d++;

        for (var i:Number=0; i<myXML.children().length(); i++) {

            listMC=new MovieClip();


            LIST.addChild(listMC);

            listMC.addEventListener(MouseEvent.CLICK,listClick);
        }

        listArray.push(LIST);
        LISTmc.addChild(LIST);
        addChild(LISTmc);

        }

private function listClick(event:MouseEvent):void {
        var currentListArray=listArray[listArray.length-1];

        //trace from which position of Array
        trace(listArray.length-event.target.parent)
    }


why do you lookup the parent? maybe use mouseChildren = false, so event.target points to you clip ... to find the index, use Array::indexOf, so should be something like trace(listArray.indexOf(event.target)) in the end ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜