Hi all,
I'm new to flash / xml and I have no idea why I can't understand how to do this. Can someone possibly explain to me the actionscript and xml needed to output several strings into dynamic text boxes in flash?
My xml looks like this:
| Quote: |
<?xml version="1.0"?>
<shoe>
<support="Support: Neutral" />
<weight="Weight: 12.7 oz." />
<fit="Fit: normal" />
<widths="Additional Widths: N/A" />
<information="Nike's best cushioning shoe, nicely improved. The men's Air Max Moto+5 features articulated air and improved flexibility to let you get out and run. "/>
</shoe> |
My actionscript 2.0 looks like this:
| Quote: |
on (release) {
if (getxmldata.loaded){
pic1_mc._alpha = 100;
var p = getxmldata.firstChild;
xmldoc = getxmldata.childNodes;
node_name=p.nodeName;
support_txt=this.firstChild.nodeValue;
weight_txt=p.attributes.weight;
fit_txt=p.attributes.fit;
widths_txt=p.attributes.widths;
information_txt=p.attributes.information;
} |
I have dynamic text boxes labeled information_txt, widths_txt, fit_txt, weight_txt, support_txt, node_name, and xmldoc. HELP!!!
yes. in order to make a text field display text you can make it just
that wont work, however
will make the text = that. so you need to add .text
I'm not sure if I'm following. I made changes to the actionscript according to what you said I think.
| Code: |
on (release) {
shoetype_mc._visible = true;
object._visible = false;
text_txt._alpha = 0;
slider._alpha = 0;
scrollbar._alpha = 0;
whitecover_mc._visible = true;
if (getxmldata.loaded){
pic1_mc._alpha = 100;
shit_txt.text = p.attributes.shit;
var p = getxmldata.firstChild;
xmldoc.text = getxmldata.childNodes;
node_name.text=p.nodeName;
support_txt.text=this.firstChild.nodeValue;
weight_txt.text=p.attributes.weight;
fit_txt.text=p.attributes.fit;
widths_txt.text=p.attributes.widths;
information_txt.text=p.attributes.information;
}
}
|
However, I still cannot see any outputted text, except for now node_name outputs "null", and shit_txt outputs "undefined", which doesn't seem very promising.
I'm so confused. Help!!!
Right-click & save on the following files for the fla and xml.
http://www.pwn3rstc.com/Moto.fla
http://www.pwn3rstc.com/xml.xml
m-productions, thanks for the help you gave me. If anyone could possibly take a look at my fla and xml I'd really appreciate it. Thanks.
i honestly know absolutely nothing about Flash or Actionscript.
However... maybe i can offer a suggestion?
| Quote: |
| Code: | <?xml version="1.0"?>
<shoe>
<support="Support: Neutral" />
<weight="Weight: 12.7 oz." />
<fit="Fit: normal" />
<widths="Additional Widths: N/A" />
<information="Nike's best cushioning shoe, nicely improved. The men's Air Max Moto+5 features articulated air and improved flexibility to let you get out and run. "/>
</shoe> |
|
That's not XML.
This is not a legal XML tag:
| Code: |
| <support="Support: Neutral" /> |
This is:
| Code: |
| <support support="Support: Neutral"/> |
Or:
| Code: |
| <support>Support: Neutral</support> |
Like i said, i don't know anything about actionscript, but it seems to me that your code is mostly attempting to read values in attributes, so what you want is something like this:
| Code: |
<?xml version="1.0"?>
<shoe>
<support>Support: Neutral</support>
<weight weight="Weight: 12.7 oz." />
<fit fit="Fit: normal" />
<widths widths="Additional Widths: N/A" />
<information information="Nike's best cushioning shoe, nicely improved. The men's Air Max Moto+5 features articulated air and improved flexibility to let you get out and run. "/>
</shoe> |
So your actionscript might look something more like this:
| Code: |
support_txt.text = getxmldata.firstChild.nodeValue;
(I assume that getxmldata.firstChild is the <support> tag)
var xmldata = getxmldata.childNodes;
weight_txt.text = xmldata[1].attributes.weight;
fit_txt.text = xmldata[2].attributes.fit;
(and so on) |
☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺
For the record, i think the reason you see "undefined" for shit_txt is because you set shit_txt with p.attributes.shit before you set p.
Thanks for the help Indi. I changed the xml file to the following:
| Code: |
<?xml version="1.0"?>
<shoe>
<support support="Support: Neutral" />
<weight weight="Weight: 12.7 oz." />
<fit fit="Fit: normal" />
<widths widths="Additional Widths: N/A" />
<information information="Nike's best cushioning shoe, nicely improved. The men's Air Max Moto+5 features articulated air and improved flexibility to let you get out and run."/>
<shit shit="shit: shit"/>
</shoe> |
like you said. My actionscript is now the following:
| Code: |
if (getxmldata.loaded){
pic1_mc._alpha = 100;
support_txt.text = getxmldata.firstChild.nodeValue;
var xmldata = getxmldata.childNodes;
weight_txt.text = xmldata[1].attributes.weight;
fit_txt.text = xmldata[2].attributes.fit;
widths_txt=xmldata[3].attributes.widths;
information_txt=xmldata[4].attributes.information;
} |
and nothing is showing up. HELP!!!
| bigdbag wrote: |
Thanks for the help Indi. I changed the xml file to the following:
| Code: | <?xml version="1.0"?>
<shoe>
<support support="Support: Neutral" />
<weight weight="Weight: 12.7 oz." />
<fit fit="Fit: normal" />
<widths widths="Additional Widths: N/A" />
<information information="Nike's best cushioning shoe, nicely improved. The men's Air Max Moto+5 features articulated air and improved flexibility to let you get out and run."/>
<shit shit="shit: shit"/>
</shoe> |
like you said. My actionscript is now the following:
| Code: |
if (getxmldata.loaded){
pic1_mc._alpha = 100;
support_txt.text = getxmldata.firstChild.nodeValue;
var xmldata = getxmldata.childNodes;
weight_txt.text = xmldata[1].attributes.weight;
fit_txt.text = xmldata[2].attributes.fit;
widths_txt=xmldata[3].attributes.widths;
information_txt=xmldata[4].attributes.information;
} |
and nothing is showing up. HELP!!! |
the "main" action script is correc,t the only errors would be how you are talking to the XML, aka how your reading it with your script. I never use XML with flash, I never have a need to. I use simple and easy .txt files because they are easier to write back to, and MYsql Databases.
i'd recommend going with what m-productions suggests. He knows what he's talking about, i don't.
i can make a recommendation, though. Step back, start over, scale it down. Right now you've got 20-ish lines of code that don't work and you don't know where the problem is. So step back. Start over. And scale it down to one line of code at a time.
Actionscript has to have some kind of simple display function you can use as a trace function, like JavaScript's alert() or Win32API's MessageBox(). i'll call it alert() for now. So use it line by line to figure out exactly which lines are being executed and which aren't. And don't try to do two things at once (like getting a value from the XML file and setting the text box at the same time). So start with this:
| Code: |
on (release) {
alert("If you see this message, you know on (release) is being called ok");
} |
Then:
| Code: |
on (release) {
alert("If you see this message, you know on (release) is being called ok");
if (getxmldata.loaded) {
alert("If you see this message, you know the if statement is working.");
}
} |
Then:
| Code: |
on (release) {
alert("If you see this message, you know on (release) is being called ok");
if (getxmldata.loaded) {
alert("If you see this message, you know the if statement is working.");
support_txt.text = "If this is in the support text box, then you know that's working";
}
} |
And so on, checking each thing one step at a time. Whenever something doesn't work, stop and find out why. Even something as trivial as setting the text in the support text box might fail because of a typo. You can catch that quickly instead of looking at 20 lines of code and scratching your head, wondering where the problem might be.
| Indi wrote: |
Actionscript has to have some kind of simple display function you can use as a trace function, like JavaScript's alert() or Win32API's MessageBox(). |
yes there is, it is called the trace() functions
trace(yourvar) or trace("string")
so where indi has used alert() place a trace() instead.
| Code: |
on (release) {
trace("If you see this message, you know on (release) is being called ok");
if (getxmldata.loaded) {
trace("If you see this message, you know the if statement is working.");
support_txt.text = "If this is in the support text box, then you know that's working";
}
}
|
also, you might wish to check this out
http://www.actionscript.org/resources/articles/9/1/XML-101/Page1.html
Thank you all for the help.
M-Productions, how do you use text files in flash?
its very simple.
Flash Script
| Code: |
//sets our vars
sender = new LoadVars();
getinfo = new LoadVars();
// makes it so it wont load from cash
sender.cacheKiller = new Date().getTime();
sender.sendAndLoad("http://www.yoursite.com/wyourfile.txt", getinfo, "GET");
getinfo.onLoad = function(success:Boolean) {
if (success) {
// place all your scripts here, for test
trace(getinfo.test)
trace(test)
}
}
|
You text file needs to hold vars like this
| Code: |
&var1=content of var&
&test=hello world&
&width= w/e you place for width&
|
Oh wow... Thanks for the help M-productions. This is such a better solution for my situation. I'm eternally grateful. 
Np, happy to help, post if you have any more questions with .txt files.
Unfortunately I cannot figure this out. This is my actionscript:
| Code: |
on (release) {
//sets our vars
sender = new LoadVars();
getinfo = new LoadVars();
// makes it so it wont load from cache
sender.cacheKiller = new Date().getTime();
sender.sendAndLoad("http://www.blahblahblah.info.txt", getinfo, "GET");
getinfo.onLoad = function(success:Boolean) {
if (success) {
// place all your scripts here, for test
support_txt.text = this.support;
}
}
|
I don't think my
| Code: |
| support_txt.text = this.support; |
line is correct. My text file looks like this:
| Code: |
| &support=content of var& |
Help!!!
EDIT: Sorry nevermind. I changed it up a bit and it worked.
kk, lol what was the problem? cuase the code likes right there. Anyway let me know if there are any other bugs.