Hi all,
I'm trying to load external text into a dynamic text box in flash with no luck.
For speed purposes I have been copying and pasting the text straight into the dynamic text box and using scroll
'up & down' arrows, which has been working fine.
Now the client has some text in a word file with a table of information and prices for services they offer, I've tried
lots of 'loading external text into flash' tutorials but with no luck.
I've even tried converting it to xml and then trying to load that, but I was just getting errors.
Could anyone post some simple steps to show me how I would load the text from word or as xml file
(infact anything that would keep the table of info), I can't use txt for obvious reasons.
Thx in advance
Sonder!!
External Text Problems
Started by sonder, Mar 14 2007 02:07 PM
4 replies to this topic
#1
Posted 14 March 2007 - 02:07 PM
#2
Posted 14 March 2007 - 02:47 PM
Ok, so there is some code from a project I'm working on. It loads up xml using the params passed into the loadxml function. xmlString is the url to the xml, and c:Round is data typed as a class that I have...you can replace that with the scope of the object or movieclip where the parseXML function resides. Dont forget to change the data type on it as well.
Once the xml has been loaded, the parseXML function is called. You have a few properties you can use to "navigate" through your xml.
firstChild - the firstChild node
nextSibling - the next node on the same level as the node you are accessing this property from
lastSibling - same as above, but the last sibling.
childNodes - an array of all the childNodes. For example, one of my nodes is: <questions> and within that node, I have 6 <question> nodes. childNodes would return an array with all 6 <question> nodes in it.
Those are the basic properties that youll use. Google flash xml tutorials for more info on it, or check out the live docs...or post back here.
Once I sort out the data, I assign it all to properties in an object, then put that object into an array. That way I can easily get it later on.
Hope this helps, good luck.
Once the xml has been loaded, the parseXML function is called. You have a few properties you can use to "navigate" through your xml.
firstChild - the firstChild node
nextSibling - the next node on the same level as the node you are accessing this property from
lastSibling - same as above, but the last sibling.
childNodes - an array of all the childNodes. For example, one of my nodes is: <questions> and within that node, I have 6 <question> nodes. childNodes would return an array with all 6 <question> nodes in it.
Those are the basic properties that youll use. Google flash xml tutorials for more info on it, or check out the live docs...or post back here.
Once I sort out the data, I assign it all to properties in an object, then put that object into an array. That way I can easily get it later on.
Hope this helps, good luck.
function loadxml(xmlString:String, c:Round){
var tmd:XML = new XML();
tmd.ignoreWhite = true;
tmd.load(xmlString);
tmd.onLoad = function(bSuccess:Boolean):Void{
if(!bSuccess){
trace("xml load error");
} else {
trace("XML Loaded");
c.parseXML(tmd);
}
}
}
function parseXML(xmlFile:XML){
// build dataArr
aDataArr = new Array();
trace("parsing");
var xm:XML = xmlFile;
//trace(xm);
var xnRoot:XMLNode = xm.firstChild; // <event>
var aRounds:Array = xnRoot.firstChild.childNodes; // <rounds>
for(var ii:Number = 0; ii < aRounds.length; ii++){
var aQues:Array = aRounds[ii].firstChild.childNodes;
for(var bb:Number = 0; bb < aQues.length; bb++){
var oDataObj:Object = new Object();
oDataObj.nRoundNum = Number(aRounds[ii].attributes["ID"].toString())
oDataObj.nCurrentQ = aQues[bb].attributes["ID"].toString();
var xnDesc:XMLNode = aQues[bb].firstChild;
oDataObj.question = xnDesc.toString();
var xnImg:XMLNode = xnDesc.nextSibling;
oDataObj.image = xnImg.toString();
var xnRem:XMLNode = xnImg.nextSibling;
oDataObj.rem = xnRem.toString();
var xnAns:XMLNode = xnRem.nextSibling;
var aAns:Array = xnAns.childNodes;
oDataObj.ans1 = aAns[0].attributes["Description"].toString();
var xnHint:XMLNode = xnAns.nextSibling;
var aHint:Array = xnHint.childNodes;
oDataObj.clue1 = aHint[0].attributes["Description"].toString();
aDataArr.push(oDataObj);
}
}
}
#3
Posted 14 March 2007 - 03:39 PM
Nice crash course on XML... but why do you use ii & bb for your for loops? I just use i, then count down the alphabet. Never seen people do it that way...
But I guess their variables
But I guess their variables
#4
Posted 14 March 2007 - 04:55 PM
I use double letters because if I need to search in my loops to replace a loop counter...like if I screw up, or whatever, its easier to search for double letters than it is single. As far as using bb, its close to N which follows right after when I do the data typing. Just a habbit Ive formed, I guess. After bb, I typically go zz...no idea why there. Its just how I do things.
#5
Posted 15 March 2007 - 03:35 PM
Alright, fair enough
Edited by Ben, 15 March 2007 - 03:35 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
