xml - UILoader does not act as MovieClip for Drag and drop; How can you make UILoader to behave like MovieClip -
i wrote code below counselors saw here main goal import images xml main stage , play them "drag , drop function"
when turn on fine, when click on pictures "drag , drop function" message
typeerror: error #1034: type coercion failed: cannot convert fl.containers::uiloader@1a52f1f1 flash.display.movieclip. @ forgallery_fla::maintimeline/item_onmousedown() typeerror: error #1034: type coercion failed: cannot convert fl.containers::uiloader@1a52f1f1 flash.display.movieclip. @ forgallery_fla::maintimeline/item_onmouseup()
how fix problem , make uiloader uiloader
import fl.containers.uiloader; import flash.net.urlloader; import flash.net.urlrequest; import flash.events.event; var count:number = 0; //requires: // uiloader control in library var xmlloader:urlloader= new urlloader(); var myxml:xml = new xml ; var uiloader:uiloader= new uiloader(); xmlloader.addeventlistener(event.complete, loadxml); xmlloader.load(new urlrequest("gallery.xml")); function loadxml(e:event):void { myxml = new xml(e.target.data); trace(myxml) for(var i:int = 0; <2; i++) { root["pic"+i].source = myxml.pic[i]; } } var dragarray:array = [pic0, pic1]; for(var i:int = 0; < dragarray.length; i++) { dragarray[i].buttonmode = true; dragarray[i].addeventlistener(mouseevent.mouse_down, item_onmousedown); dragarray[i].addeventlistener(mouseevent.mouse_up, item_onmouseup); } function item_onmousedown(event:mouseevent):void { var clip:movieclip = movieclip(event.currenttarget); addchild(clip); //bring front clip.startdrag(); } function item_onmouseup(event:mouseevent):void { var clip:movieclip = movieclip(event.currenttarget); clip.stopdrag(); }
the xml tree is
<?xml version="1.0" encoding="utf-8"?> <gallery height="300" width="300" > <pic>p1.jpg</pic> <pic>p2.jpg</pic> <pic>p3.jpg</pic> </gallery>
you don't have cast uiloader
movieclip
. startdrag
method of sprite
. uiloader
sprite
, not movieclip
.
function item_onmousedown(event:mouseevent):void { var clip:sprite = sprite(event.currenttarget); addchild(clip); //bring front clip.startdrag(); }
you have found out in uiloader
reference.
Comments
Post a Comment