XML-Datei in ein Textfeld Laden

W

wolf007

Ich habe ein Text-Feld in Flash erstellt und da soll die XML-Datei reigeladen werden, das soll mit Aktion XML Load gehen . Man soll den Text dan mit zwei Feilen Hoch und Runter bewegen können.
Mit einer normalen Text-Date geht das ja auch aber wen ich das mit einer XML-Datei machen will geht das nicht.:confused: :confused: :confused:
 
hier is nen text der schon seit dekaden auf meinem rechner verstaubt, ich hoffe er hilft dir...


I've seen a lot of questions about loading variables from a text file. My suggestion for f5, use XML !

Here is cut and paste code, just put this into frame1 of any movie, and volia, you can load variables from nice looking XML


var varsXML = new XML();
varsXML.onLoad = loadVars;
varsXML.load("vars.xml");
stop();

function loadVars(success) {
if (success) {
var item = varsXML.firstChild.firstChild;
while (item != null) {
eval(item.attributes.NAME) = item.attributes.VALUE;
item = item.nextSibling;
}
_root.gotoAndPlay("varsLoaded");
} else {
_root.gotoAndPlay("errorLoadingXML");
}
}

The "vars.xml" file should look like this

<VARS>
<ITEM NAME="stuff" VALUE="cool stuff"/>
<ITEM NAME="things" VALUE="lots of things"/>
<ITEM NAME="xpos" VALUE="100"/>
<ITEM NAME="ypos" VALUE="100"/>
</VARS>

where each ITEM is a variable created, the name of the variable is NAME and the value inserted is VALUE. easy enough ?

make sure the _root.gotoAndPlay("varsLoaded") points to the label or frame where you want your movie to play.



here's the fla and sample xml file.

Feel free to use it, share it, take credit for, or print and mail to your mother.

http://www.webwave.com/flashexamples/vars.fla
http://www.webwave.com/flashexamples/vars.xml

(while im talking to myself)
... and if you want to add support for muliline txt boxes

change this line

eval(item.attributes.NAME) = item.attributes.VALUE;


to this
eval(item.attributes.NAME) += item.attributes.VALUE + chr(10);


then in your XML, just add one item per line, with the NAME matching your mulilined text box.

<ITEM NAME="stuff" VALUE="line 1 of cool stuff"/>
<ITEM NAME="stuff" VALUE="line 2 of cool stuff"/>
<ITEM NAME="stuff" VALUE="line 3 of cool stuff"/>





·kuat·
 
Zurück