开发者

receive and pass values with XML, AS3

开发者 https://www.devze.com 2022-12-22 19:13 出处:网络
My example imports XML and has an object rotating on stage. The rotating object is called enemy corresponds to ENEMY in the XML. How do I set the rotation variable to receive values from XML?

My example imports XML and has an object rotating on stage. The rotating object is called enemy corresponds to ENEMY in the XML. How do I set the rotation variable to receive values from XML?

REASON

It seems more difficult to set up variables using external data. I want to understand it better.

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 MODIFIED

=- 100 or =+ 100 rotates and stops

-= 100 or =+ 100 rotates constantly

<?xml version="1.0" encoding="utf-8"?>
<BADGUYS>
<ENEMY TITLE="stic开发者_如何学编程ky">100</ENEMY>
<ROGUE TITLE="slimy">1000</ROGUE>
</BADGUYS>


enemy.rotationY = Number(myXML.ENEMY.text()); 


If I remember correctly the way to do this it should be :

enemy.rotationY = myXML.ENEMY;

Take a look at this : http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/XMLList.html

0

精彩评论

暂无评论...
验证码 换一张
取 消