receive and pass values with XML, AS3
Posted
by VideoDnd
on Stack Overflow
See other posts from Stack Overflow
or by VideoDnd
Published on 2010-03-08T19:26:52Z
Indexed on
2010/03/09
6:21 UTC
Read the original article
Hit count: 265
flash
|actionscript-3
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.
here's a link http://videodnd.weebly.com/
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;
//enemy.rotationY = myXML.ENEMY.*;
}
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
enemy.xml
ENEMY is set to -100, use what you like
<?xml version="1.0" encoding="utf-8"?>
<BADGUYS>
<ENEMY TITLE="sticky">-100</ENEMY>
<ROGUE TITLE="slimy">-1000</ROGUE>
</BADGUYS>
© Stack Overflow or respective owner