Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3988418
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:14:58+00:00 2026-05-20T06:14:58+00:00

this is a repost of a previous question with more info this time. The

  • 0

this is a repost of a previous question with more info this time.

The files: 2shared.com/file/hRKhEiqh/Script_Test.html and 2shared.com/video/UZNmqzXt/a_anconeus.html

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 on MC:
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 happens after the MOUSE_DOWN event finishes, I’m not sure exactly when.

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.

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.

To duplicate this behavior, you need an external AS3 SWF with two at least two MC’s with instance names “drag01” and “drop01” or something that matches the keywords ‘drag’ and ‘drop’. Point the String variable ‘SWF’ to that file and you should see the duplication problem.

Thanks and regards
Cameron

Edit: new trimmed code, copied into a blank AS 3.0 file with the same errors.

    import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.net.URLLoader;




var swf:String = "a_anconeus.swf";
loadSWF(swf);

stage.addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStageReport, true);
stage.addEventListener ( Event.ADDED_TO_STAGE , onAddedToStageReport , true ) ;

function onRemovedFromStageReport (evt:Event)
{
    {
        trace("REMOVED: " + evt.target.name + " at depth: " + evt.target.parent.getChildIndex(evt.target));
    }
}


function onAddedToStageReport (evt:Event)
{
    {
        trace("ADDED: " + evt.target.name + " at depth: " + evt.target.parent.getChildIndex(evt.target));
    }
}

function onDragMouseDown(event:MouseEvent):void
{
    var drag:MovieClip = MovieClip(event.target);
    var topPosition:uint = drag.parent.numChildren - 1;
    trace("click: "+drag.name +", ontarget = "+drag.ontarget + ", current z: " + drag.parent.getChildIndex(drag) + " new z: " + topPosition);
    //drag.parent.setChildIndex(drag, topPosition);
    var indexToDelete:int = drag.parent.getChildIndex(drag);

//this.parent.removeChild(this);
        trace("index to delete: " + indexToDelete +", what's there: " + drag.parent.getChildAt(indexToDelete).name);
        drag.startDrag();
        //drag.parent.setChildIndex(drag, drag.parent.numChildren-1); //set child depth to top
        trace("after change, what's there: " + drag.parent.getChildAt(indexToDelete).name);
        //drag.parent.swapChildren(drag, drag.parent.getChildAt(drag.parent.numChildren -1));


}

function onDragMouseUp(event:MouseEvent):void
{
    trace("mouse up: "+event.target.name + ", index: " +event.target.parent.getChildIndex(event.target));
    var drag:MovieClip = MovieClip(event.target);

    drag.stopDrag(); //Movieclips have simple drag methods

}

/*function dragEnterFrameHandler(event:Event):void {

    var drag:MovieClip = MovieClip(event.target);

    if (drag.mousedown == false)
    {

        if (drag.onTarget == true)
        {
            //send it to the drop X/Y
            drag.x -= (drag.x - drag.dropon.x)/5;
            drag.y -= (drag.y - drag.dropon.y)/5;
        }

        else if (drag.onTarget == false)
        {
            drag.x -= (drag.x - drag.homeX)/5;
            drag.y -= (drag.y - drag.homeY)/5;
        }
    }
}*/



function loadSWF(filepath:String)
{

    trace("calling loader");
    var loader:Loader = new Loader();
    var url:String = filepath;
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);

    loader.load(new URLRequest(url));

}





function onAddedToStage ( evt:Event )
{
    trace("calling onAddedToStage");
    /*if (evt.target is MovieClip) //filter only movieclips
    {
        var mc:MovieClip = MovieClip(evt.target);
       // trace ( "onAddedToStage, evt: " + mc.name + ", " +(mc.parent.numChildren-1) ) ;

        if (String(mc.name).indexOf("drag") != -1) 
        {
            var dropString:String = String(mc.name).split("drag").join("drop");

            if (mc.parent.getChildByName(dropString))
            {
                trace("our droptarget: " + mc.dropon);
                mc.addEventListener(MouseEvent.MOUSE_DOWN, onDragMouseDown);
                mc.addEventListener(MouseEvent.MOUSE_UP, onDragMouseUp);
                mc.buttonMode = true;

            }
        }
    }*/
}

function onCompleteHandler(loadEvent:Event)
{
    trace("load complete");
    var swf:MovieClip = MovieClip(loadEvent.currentTarget.content);
    //swf.addEventListener ( Event.ADDED_TO_STAGE , onAddedToStage, true ) ;
    //trace("event attached, adding child");

trace("child add started");
    addChild(swf);

    trace("child add finished");
    var children:Number = (swf.numChildren-1);
    trace("children: " + children);
    for (var i:Number = 0; i <= children; i++)
    {
        trace("LOOP STARTS HERE");
        if (swf.getChildAt(i) is MovieClip)
        {
            //trace("MC: yes");
            var mc:MovieClip = MovieClip(swf.getChildAt(i));
            trace("name: " + mc.name);

            if (String(mc.name).indexOf("drag") != -1) 
            {
                var dropString:String = String(mc.name).split("drag").join("drop");

                if (swf.getChildByName(dropString))
                {
                    trace("removing: " + mc.name);
                    children--;
                    swf.removeChild(mc);
                    trace("removed");
                    //swf.addChild(mc);


                    /*mc.addEventListener(MouseEvent.MOUSE_DOWN, onDragMouseDown);
                    mc.addEventListener(MouseEvent.MOUSE_UP, onDragMouseUp);
                    mc.buttonMode = true;*/

                }
            }
        }
    }
trace("finish function");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T06:14:58+00:00Added an answer on May 20, 2026 at 6:14 am

    mystery solved 🙂

    looking at your swf I can see that it has two frames, so as soon as you start dragging, the next frame renders and the object comes back.

    to test this I added swf.stop(); to yout onCompleteHandler

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is sort of a follow up to a previous question, but I'll repost
I was asked to repost this question, due to the answers were not going
Sorry if this is a repost of another question; I couldn't find anything after
dudes. I hope this question is not a repost. I'm newbie on Kohana. I'm
This is related to a previous question . What I'm trying to understand now
This question is a continuation to a previous question on boost::test::unit_test. I've written a
UPDATE: this is a repost of How to make shell scripts robust to source
Apologies if this is a repost, I could not find the search terms to
Sorry if this is a repost but I couldn't quite search for it because
I initially asked this on Superuser, but somebody advised me to repost here. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.