actionscript 3 - Switching of depths causes duplication of MC -


this repost of previous question more info time.

the files: 2shared.com/file/hrkheiqh/script_test.html , 2shared.com/video/uznmqzxt/a_anconeus.html

this issue reproducible on machine new .fla project in actionscript 3.0 in flash professional cs5. it's edit of original question more information.

i'm working on project load external swf's , search through instance names matching keywords, namely 'drag' , 'drop' identify movieclip matches, attach event listeners these mc's contain d&d event listeners , code.

the specific problem switching of depths movieclips nested in dynamically loaded external swf files.

where having trouble specific commands:

swapchildrenat, setchildindex, swapchildren, removechild/addchild. i've tried 4 same problem of duplication. let me explain.

when draggable mc clicked, moved top index of dynamically loaded swf it's visible above else in swf. problem trying of these commands duplicate mc. happens this:

mouse_down event fires on mc: index of target mc recorded '2', index switch '20' (maximum index of swf) setchildindex called on target mc parent: mc.parent.setchildindex(mc, (mc.parent.numchildren-1)) mc moves index 20 instance of mc created @ layer located (index 2), happens after mouse_down event finishes, i'm not sure when.

this duplicate has been confirmed using event.added_to_stage listener attached stage catch every object of movieclip types added stage. i've inspected swf confirm there's no duplicate movieclips, traces confirm this.

similar posts mention same duplication problem no 1 has solution i've found work in 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 last note, if comment out index swap statement, code works mc staying on lower z-index instead of being on top. unfortunately that's not going work solution since i'm not building external swf's.

to duplicate behavior, need external as3 swf 2 @ least 2 mc's instance names "drag01" , "drop01" or matches keywords 'drag' , 'drop'. point string variable 'swf' file , should see duplication problem.

thanks , regards cameron

edit: new trimmed code, copied blank 3.0 file 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 + " @ depth: " + evt.target.parent.getchildindex(evt.target));     } }   function onaddedtostagereport (evt:event) {     {         trace("added: " + evt.target.name + " @ 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 delete: " + indextodelete +", what's there: " + drag.parent.getchildat(indextodelete).name);         drag.startdrag();         //drag.parent.setchildindex(drag, drag.parent.numchildren-1); //set child depth 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 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 movieclip) //filter 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);     (var i:number = 0; <= children; i++)     {         trace("loop starts here");         if (swf.getchildat(i) 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"); } 

mystery solved :)

looking @ swf can see has 2 frames, start dragging, next frame renders , object comes back.

to test added swf.stop(); yout oncompletehandler


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -