我在这里看到的辅导员下面写了这段代码 它的主要目标是将图像从xml导入主舞台,然后使用“拖放功能”进行播放
当我打开它时一切都很好, 但是当我点击图片到“拖放功能”时 我收到此消息
TypeError: Error #1034: Type Coercion failed: cannot convert fl.containers::UILoader@1a52f1f1 to flash.display.MovieClip.
at forgallery_fla::MainTimeline/item_onMouseDown()
TypeError: Error #1034: Type Coercion failed: cannot convert fl.containers::UILoader@1a52f1f1 to flash.display.MovieClip.
at forgallery_fla::MainTimeline/item_onMouseUp()
如何解决问题并将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; i <2; i++)
{
root["pic"+i].source = myXML.pic[i];
}
}
var dragArray:Array = [pic0, pic1];
for(var i:int = 0; i < 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 to the front
clip.startDrag();
}
function item_onMouseUp(event:MouseEvent):void {
var clip:MovieClip = MovieClip(event.currentTarget);
clip.stopDrag();
}
XML树是
<?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>
答案 0 :(得分:0)
您无需将UILoader
投射为MovieClip
。 startDrag
是Sprite
的一种方法。 UILoader
是Sprite
,而不是MovieClip
。
function item_onMouseDown(event:MouseEvent):void {
var clip:Sprite = Sprite(event.currentTarget);
addChild(clip); //bring to the front
clip.startDrag();
}
你可以在UILoader
reference中找到这个。