您好,我决定使用另一张图片来展示我的目标,我想知道是否可以在成功拖放时加载多个 XML 文件?是否可以在取消目标时重置或切换到空白 XML?
我的代码已经和我的其他代码混在一起了,基本上如果圆圈是按钮,每次都会加载不同的XML,我想或多或少地合并两组代码,这样当圆圈/雕像被拖过去时,“ Circle one In Place Successfully”消息将出现,并且我拥有的 xml 文件也将加载。当我试图实现它时,可悲的是,总体结果是无数错误,这让我不敢说。
哦,我也想清楚这一点,这不是我之前关于拖放的问题的抵消,这更多的是我尝试不同的方法并学习一般的 XML,所以我最终使用它作为如果可以在每次拖动时加载不同的 XML,则用于测试情况的“骨架”。
import flash.net.URLLoader;
import flash.events.Event;
var circles:Array = [circle1_mc, circle2_mc, circle3_mc];
circle1_mc.myname = "xmlFile1";
circle2_mc.myname = "xmlFile2";
circle3_mc.myname = "xmlFile3";
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
function LoadXML (evt:Event):void
{
trace ("Load completed");
xmlData = XML(xmlLoader.data);
}
var bArray:Array = [circle1_mc, circle2_mc, circle3_mc];
for (var k:Number = 0; k<bArray.length; k++)
{
bArray[k].buttonMode = true;
bArray[k].addEventListener (MouseEvent.CLICK,changeXMLPath);
}
function changeXMLPath (evt:MouseEvent):void
{
for (var i:Number = 0; i<bArray.length; i++)
{
if (evt.target.myname == bArray[i].myname)
{
xmlLoader.load (new URLRequest(evt.target.myname+".xml"));
xmlLoader.addEventListener (Event.COMPLETE,LoadXML);
}
}
}
for each(var circleMC:MovieClip in circles)
{
circleMC.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
circleMC.addEventListener(MouseEvent.MOUSE_UP, dropIt);
circleMC.startX = circleMC.x;
circleMC.startY = circleMC.y;
}
function pickUp(event:MouseEvent):void
{
reply_txt.text = "";
event.target.startDrag(true);
event.target.parent.addChild(event.target);
}
function dropIt(event:MouseEvent):void
{
event.target.stopDrag();
if(event.target.hitTestObject(target_mc)){
event.target.buttonMode = false;
event.target.x = target_mc.x;
event.target.y = target_mc.y;
for each(var circleMC:MovieClip in circles)
{
if(event.target != circleMC)
{
circleMC.x = circleMC.startX;
circleMC.y = circleMC.startY;
}
if(event.target.name == "circle1_mc"){
reply_txt.text = "Statue1 In Place Successfully";
};
if(event.target.name == "circle2_mc"){
reply_txt.text = "Statue2 In Place Successfully";
};
if(event.target.name == "circle3_mc"){
reply_txt.text = "Statue3 In Place Successfully";
};
}
}
else
{
event.target.x = event.target.startX;
event.target.y = event.target.startY;
event.target.buttonMode = true;
}
}