2

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.com/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

2
  • can we also see your onDragMouseUp function?
    – Jordan
    Feb 18, 2011 at 1:45
  • I haven't got around to testing that function yet, but added for clarity.
    – Cameron
    Feb 18, 2011 at 2:10

2 Answers 2

0

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.

6
  • Thanks for the suggestion. I've tried this: var tempParent:MovieClip = MovieClip(drag.parent); tempParent.removeChild(drag); tempParent.addChild(drag); But no luck, this method is leaving a duplicate behind as well. If you need any more information about the project feel free to ask.
    – Cameron
    Feb 18, 2011 at 1:01
  • If you just removeChild, is it still on the stage? The duplication is throwing me.
    – TNC
    Feb 18, 2011 at 1:12
  • Yea the duplication is confusing me too, there must be some other code that we should see because I just set up and example with your code and I'm not seeing any duplication.
    – Jordan
    Feb 18, 2011 at 1:19
  • Just removing the MC causes a duplicate to be left behind as well as removing the original MC. I've got a loader code that might provide some insight, I'll edit the question to reflect that.
    – Cameron
    Feb 18, 2011 at 1:35
  • If you trace out your swf.numChildren and var swf:MovieClip = MovieClip(loadEvent.currentTarget.content); addChild(swf); to make sure you're only attaching one copy, do that work?
    – TNC
    Feb 18, 2011 at 3:18
0

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(); !!!

1
  • 1
    Hi there, I actually reposted this question later on with a bit more detail, here's the link: stackoverflow.com/questions/5099988/… The answer was that the child SWF I was loading had 2 frames and I didn't call a childSWF.stop() command, using that fixed it.
    – Cameron
    Apr 5, 2011 at 4:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.