I have a xml file with code in it and i need to integrate that code in as3. How can i do that?

  • Replies:0
  • OpenNot stickiedAnswered
  • Forum posts: 42

Sep 29, 2014 11:38:17 AM via Website

I want to add several lines of code to flash AS3. How would i be able to do that if those lines are in a xml and the data that is needed is taken with a function that loads the xml. I need to add those lines in flash? How can i do that?

Example:
<!-- "Level id" number is not required. Just I added it for fast calculating -->

<!-- Page 1 -->

<Level id="1" star3="6" star2="10">
<Row>2,2,2,2</Row>
<Row>2,2,0,0</Row>
<Row>2,2,2,2</Row>
<Row>1,1,4,4</Row>
<Row>1,1,4,4</Row>
</Level>

<Level id="2" star3="8" star2="12">
<Row>2,2,2,2</Row>
<Row>2,2,2,2</Row>
<Row>0,1,1,0</Row>
<Row>3,3,4,4</Row>
<Row>3,3,4,4</Row>
</Level>

<Level id="3" star3="8" star2="12">
<Row>1,0,1,1</Row>
<Row>1,0,1,1</Row>
<Row>1,1,4,4</Row>
<Row>1,1,4,4</Row>
<Row>1,1,1,1</Row>
</Level>

<Level id="4" star3="8" star2="12">
<Row>3,1,1,0</Row>
<Row>3,1,1,0</Row>
<Row>2,2,2,2</Row>
<Row>3,3,4,4</Row>
<Row>3,3,4,4</Row>
</Level>
.
.
.
etc

The function to load this xml is the following one:
//playBtn.visible=false;
loadXML();
//loading data from the xml file.
function loadXML():void {
var loader:URLLoader=new URLLoader();
loader.addEventListener(Event.COMPLETE,completeXMLHandler);
//defining request.;
var request:URLRequest = new URLRequest("data.xml";);
//try catch any error
try {
loader.load(request);
} catch (error:Error) {
trace('error');
}
}

//loading function
function completeXMLHandler(event:Event):void {

var loader:URLLoader = URLLoader(event.target);
var result:XML = new XML(loader.data);
//defining new xml document
var myXML:XMLDocument=new XMLDocument();
myXML.ignoreWhite = true;
myXML.parseXML(result.toXMLString());
//defining node;
var node:XMLNode = myXML.firstChild;
//defining levelNum from the lenght of the node
totalLevel = int(node.childNodes.length);
//pushing the words and their clues to the array
//creating a temporary array for each level, than pushing temporary array to the main array (dataArray)
for (var i:int=0; i<totalLevel; i++) {
scoreArray.push(9999)
var temp_array:Array=new Array();
var row:int = int(node.childNodes[i].childNodes.length);
starInfoArray.push(node.childNodes[i].attributes.star3+"_"+node.childNodes[i].attributes.star2);
for (var j:int=0; j<row; j++) {
var myData = node.childNodes[i].childNodes[j].firstChild.nodeValue;
temp_array.push(myData);
}
dataArray.push(temp_array);
}
}

Please help me