我的示例导入XML并在舞台上旋转对象。旋转对象称为 enemy 对应于XML中的 ENEMY 。 如何设置旋转变量以接收来自XML的值?
原因
使用外部数据设置变量似乎更加困难。我想更好地理解它。
rotation.fla
//LOAD XML
var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("enemy.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
//PARSE XML
function processXML(e:Event):void {
myXML = new XML(e.target.data);
trace(myXML.ROGUE.*);
trace(myXML);
//TEXT
var text:TextField = new TextField();
text.text = myXML.ENEMY.*;
addChild(text);
}
//ROTATION
function enterFrameHandler(event:Event):void
{
//==>CODE I WANT TO CHANGE<==
enemy.rotationY += 10;
/*
//ANSWER
enemy.rotationY -= Number(myXML.ENEMY.text());
*/
}
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
enemy.xml 修改了
= - 100或= + 100旋转并停止
- = 100或= + 100不断旋转
<?xml version="1.0" encoding="utf-8"?>
<BADGUYS>
<ENEMY TITLE="sticky">100</ENEMY>
<ROGUE TITLE="slimy">1000</ROGUE>
</BADGUYS>
答案 0 :(得分:0)
如果我没记错的话,那应该是:
enemy.rotationY = myXML.ENEMY;
看看这个:http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/XMLList.html
答案 1 :(得分:0)
enemy.rotationY = Number(myXML.ENEMY.text());