- Forum posts: 42
Sep 29, 2014, 11:38:17 AM via Website
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
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.