0

我在我在这里看到的辅导员下面写了这段代码它的主要目标是将图像从 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>
4

1 回答 1

0

您不必将您的UILoader作为MovieClip. startDrag是一种方法SpriteUILoader是一个Sprite,不是一个MovieClip

function item_onMouseDown(event:MouseEvent):void {
    var clip:Sprite = Sprite(event.currentTarget);
    addChild(clip); //bring to the front
    clip.startDrag();
}

您可以在UILoader参考资料中找到这一点。

于 2013-05-14T12:27:15.597 回答