all groups > flash data integration > january 2006 >
You're in the

flash data integration

group:

AARRGGHHH!!! why doesn't this work?


Re: AARRGGHHH!!! why doesn't this work? Motion Maker
1/4/2006 10:09:09 PM
flash data integration: Use typeof operator to evaluate the data received. I believe you will find
it is String.
trace(typeof(price));
trace(typeof(shipping));

To convert to a number multiply by 1 or use parseFloat and parseInt

var price = products.firstChild.nextSibling.childNodes * 1
var price = parseFloat(products.firstChild.nextSibling.childNodes )

Consider strict typing variables to get more out of the compiler.
var price:Number = parseFloat(products.firstChild.nextSibling.childNodes )


--
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
[quoted text, click to view]
:frown;
Okay... I am trying to load an XML file in flash8 and declare some
variables
with the data I imported. I will trace the content of the childNode by
loading
it into a variable i.e var price = (my_xml,firstChild....ect) then
trace(price)
and I get the correct value. Here is the trouble ... I am trying to declare
a
var total which adds 2 of the varibles I declared from parsing the XML file
ie... var total = price + shipping;... below is the code and the xml file I
am
using... It's been 2 days on my own and many handfuls of hair later... help
please!!!

var products:XML = new XML();
products.ignoreWhite = true;
products.onLoad = function(success:Boolean):Void {
if (success) {
var price = (products.firstChild.nextSibling.childNodes);
var shipping = (products.firstChild.nextSibling.nextSibling.childNodes);
var total = price + shipping;
trace(price);
trace(shipping);
trace(total);
} else {
trace("Error loading XML.");
}
}
products.load("product.xml");

the xml file...

<?xml version="1.0" encoding="UTF-8"?>
<item>toaster</item>
<price>245.50</price>
<shipping>2.50</shipping>

I am recieving this error....but also recieving the values of
...price,shipping...but an NAN (which looks like NaNAnaNAnA to me now) for
the
trace of var total...

Scene 1, Binding between <unknown>.. and poop.results.product.price: The
endpoint of the binding does not exist
NaN
245.50
2.50

I programme in all kinds of languages and I have never gotten stuck this
long.... PLEASE HELP!!!

Adam
emailme@adamsimms.com

AARRGGHHH!!! why doesn't this work? adamsimms
1/4/2006 10:55:19 PM
:frown;
Okay... I am trying to load an XML file in flash8 and declare some variables
with the data I imported. I will trace the content of the childNode by loading
it into a variable i.e var price = (my_xml,firstChild....ect) then trace(price)
and I get the correct value. Here is the trouble ... I am trying to declare a
var total which adds 2 of the varibles I declared from parsing the XML file
ie... var total = price + shipping;... below is the code and the xml file I am
using... It's been 2 days on my own and many handfuls of hair later... help
please!!!

var products:XML = new XML();
products.ignoreWhite = true;
products.onLoad = function(success:Boolean):Void {
if (success) {
var price = (products.firstChild.nextSibling.childNodes);
var shipping = (products.firstChild.nextSibling.nextSibling.childNodes);
var total = price + shipping;
trace(price);
trace(shipping);
trace(total);
} else {
trace("Error loading XML.");
}
}
products.load("product.xml");

the xml file...

<?xml version="1.0" encoding="UTF-8"?>
<item>toaster</item>
<price>245.50</price>
<shipping>2.50</shipping>

I am recieving this error....but also recieving the values of
...price,shipping...but an NAN (which looks like NaNAnaNAnA to me now) for the
trace of var total...

Scene 1, Binding between <unknown>.. and poop.results.product.price: The
endpoint of the binding does not exist
NaN
245.50
2.50

I programme in all kinds of languages and I have never gotten stuck this
long.... PLEASE HELP!!!

Adam
emailme@adamsimms.com

Re: AARRGGHHH!!! why doesn't this work? Motion Maker
1/5/2006 11:45:58 AM
Looks like you are parsing the incorrect place in the XML tree. The Object
type is likely an XMLNode and not a node value property.

Post the XML and perhaps we can can help in the XML parsing if you cannot
figure it on your own.

--
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
[quoted text, click to view]
Thank you so much for your response. When I trace the variables they come
back
with the attribute (object)? the code you provided did not work with them
being
declared as an object. also the code ... price:number... comes up with a
syntax
error... this could be because I am using flash 8.... any other suggestions?

adam

Re: AARRGGHHH!!! why doesn't this work? Motion Maker
1/5/2006 12:55:41 PM
Sorry I lost track of the information available.

Your xml is fine but due to posting in the forum I cannot be sure that there
is no (non data) whitespace in the XML including no end of line characters
or tabs. That you handle in the source file or in the source server script
depending on how you do it.

Two examples below can be pasted into a blank movie on frame 1 for testing
with Control->Test movie. These are designed to simplify demonstration of
the XML parsing by Flash by avoiding an external source. Adapt to your code
by adding all the trace statements to your onLoad for debugging. Then use
what is inside the trace statements to complete your application. Example 1
should work for your current xml. Example 2 requires a modification to your
xml.


Example 1 without a wrapper node:
var testXml:String =
"<item>toaster</item><price>245.50</price><shipping>2.50</shipping>";

var my_xml:XML = new XML(testXml);
trace(my_xml.firstChild.nodeName); // output: item
trace(my_xml.firstChild.firstChild.nodeValue); // output: toaster
trace(my_xml.childNodes[0].nodeName); // output: item
trace(my_xml.childNodes[0].firstChild.nodeValue); // output:toaster

trace(my_xml.childNodes[1].nodeName); // output: price
trace(my_xml.childNodes[1].firstChild.nodeValue); // output:245.50

trace(my_xml.childNodes[2].nodeName); // output: shipping
trace(my_xml.childNodes[2].firstChild.nodeValue); // output:2.5

You might consider a wrapper node for XML. <order> ...... </order>. I simply
use <datapacket>....</datapacket>.

Example 2 with a wrapper node:
var testXml:String =
"<datapacket><item>toaster</item><price>245.50</price><shipping>2.50</shipping></datapacket>";

var my_xml:XML = new XML(testXml);
trace(my_xml.firstChild.firstChild.nodeName); // output: item
trace(my_xml.firstChild.firstChild.firstChild.nodeValue); // output: toaster
trace(my_xml.firstChild.childNodes[0].nodeName); // output: item
trace(my_xml.firstChild.childNodes[0].firstChild.nodeValue); //
output:toaster

trace(my_xml.firstChild.childNodes[1].nodeName); // output: price
trace(my_xml.firstChild.childNodes[1].firstChild.nodeValue); //
output:245.50

trace(my_xml.firstChild.childNodes[2].nodeName); // output: shipping
trace(my_xml.firstChild.childNodes[2].firstChild.nodeValue); // output:2.5


--
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
[quoted text, click to view]
I did post the XML file in the previous message. It is right under the code
if
you look hard. when I parse the tree to the data I want I get it in the
format
<price>245.50</price> ... this is after I chaged the parsing code and took
out
the childnode at the end. I probably am not parsing the data properly....
thanks for helping a newbie to xml format out..


adam

Re: AARRGGHHH!!! why doesn't this work? adamsimms
1/5/2006 4:31:19 PM
Thank you so much for your response. When I trace the variables they come back
with the attribute (object)? the code you provided did not work with them being
declared as an object. also the code ... price:number... comes up with a syntax
error... this could be because I am using flash 8.... any other suggestions?

adam
Re: AARRGGHHH!!! why doesn't this work? adamsimms
1/5/2006 5:18:42 PM
I did post the XML file in the previous message. It is right under the code if
you look hard. when I parse the tree to the data I want I get it in the format
<price>245.50</price> ... this is after I chaged the parsing code and took out
the childnode at the end. I probably am not parsing the data properly....
thanks for helping a newbie to xml format out..


adam
Re: AARRGGHHH!!! why doesn't this work? Motion Maker
1/5/2006 7:36:23 PM
Glad to help!

--
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
[quoted text, click to view]
You are AWSOME!!!!... I feel like I should pay you... It is very hard to
find a
mentor.... I will give you that title....

I got your back.... If you need something just ask...


Thanks again for the xml lesson --- by example --- I finished the shopping
cart app I was developing...

Adam

Re: AARRGGHHH!!! why doesn't this work? adamsimms
1/5/2006 10:46:26 PM
You are AWSOME!!!!... I feel like I should pay you... It is very hard to find a
mentor.... I will give you that title....

I got your back.... If you need something just ask...


Thanks again for the xml lesson --- by example --- I finished the shopping
cart app I was developing...

Adam
AddThis Social Bookmark Button