开发者

swapChildrenAt, setChildIndex, swapChildren all duplicating MC's

first time poster here.

This issue is reproducible on my machine with a new .fla project in Actionscript 3.0 in Flash Professional CS5. It's an edit of my original question with more information.

I'm working on a project to load external SWF's and search through instance names for matching keywords, namely 'drag' and 'drop' to identify movieclip matches, then attach event listeners to these MC's which contain the D&D event listeners and code.

The specific problem is the switching of depths for Movieclips nested in dynamically loaded external SWF files.

Where I am having trouble is the specific commands:

swapChildrenAt, setChildIndex, swapChildren, removeChild/addChild. I've tried all four with the same problem of duplication. Let me explain.

When a draggable MC is clicked, it is moved to the top index of the dynamically loaded SWF so it's visible above everything else in that SWF. The problem is that trying any of these commands all duplicate the MC. What happens is this:

MOUSE_DOWN event fires: Index of target MC is recorded as '2', the index we will switch to is '20' (maximum index of the SWF) setChildIndex is called on the target MC parent: mc.parent.setChildIndex(mc, (mc.parent.numChildren-1)) MC moves to index 20 then another instance of the MC is created at the layer it was located previously (index 2)

This duplicate has been confirmed using the EVENT.ADDED_TO_STAGE listener attached to the stage to catch every object of MovieClip types that is added to the stage. I've inspected the SWF to confirm there's no duplicate MovieClips, the traces also confirm this.

There are similar posts around the web mentioning the same problem with no solutions.

Similar posts mention the same duplication problem but no one has a solution that I've found will work in my case.

http://www.kirupa.com/forum/showthread.php?t=359452 http://board.flashkit.co开发者_JAVA技巧m/board/showthread.php?t=775200 http://forums.adobe.com/thread/199983

As a last note, if I comment out the index swap statement, the code works perfectly with the MC simply staying on its lower z-index instead of being on top. Unfortunately that's not going to work as a solution since I'm not building the external SWF's.

Thanks and regards Cameron


One quick way of bypassing the setChildIndex/swapChildrenAt/etc, if possible in your framework, would be to removeChild and addChild (your mc), this will guarantee it's the highest.

Just a suggestion. Hope it helps.


Yes! I have been having the same problem with "duplicate MCs". This is especially troubling when you need to move between levels or "frames" in the timeline.

All I would like to do is have the MC (target) I drag to always be on top of other draggable MCs.

One thing is for certain what is causing it is this code: setChildIndex( target, numChildren - 1 );

Oh, give me back, getNextHighestDepth(); !!!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜