• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

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

DLGames

Newbie
Aug 25, 2014
26
2
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:
<?xml version="1.0" encoding="utf-8"?>

<game>


<!-- "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.childNodes.length);
starInfoArray.push(node.childNodes.attributes.star3+"_"+node.childNodes.attributes.star2);
for (var j:int=0; j<row; j++) {
var myData = node.childNodes.childNodes[j].firstChild.nodeValue;
temp_array.push(myData);
}
dataArray.push(temp_array);
}
}

Please help me.
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones