views:

71

answers:

2

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="sticky">100</ENEMY>
<ROGUE TITLE="slimy">1000</ROGUE>
</BADGUYS>
A: 

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

Frank
`myXML` refers to the root node itself - hence `myXML.BADGUYS` would search for the `BADGUYS` child of root node.
Amarghosh
That's better - removed the down-vote.
Amarghosh
+1  A: 
enemy.rotationY = Number(myXML.ENEMY.text()); 
Amarghosh