Professional Web Applications Themes

AARRGGHHH!!! why doesn't this work? - Macromedia Flash Data Integration

: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 ...

  1. #1

    Default AARRGGHHH!!! why doesn't this work?

    :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.child Nodes);
    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
    [email]emailmeadamsimms.com[/email]


    adamsimms Guest

  2. #2

    Default Re: AARRGGHHH!!! why doesn't this work?

    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 pFloat and pInt

    var price = products.firstChild.nextSibling.childNodes * 1
    var price = pFloat(products.firstChild.nextSibling.childNo des )

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


    --
    Lon Hosford
    [url]www.lonhosford.com[/url]
    May many happy bits flow your way!
    "adamsimms" <webforumsusermacromedia.com> wrote in message
    news:dphjon$lnc$1forums.macromedia.com...
    :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.child Nodes);
    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
    [email]emailmeadamsimms.com[/email]


    Motion Maker Guest

  3. #3

    Default Re: AARRGGHHH!!! why doesn't this work?

    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

    adamsimms Guest

  4. #4

    Default Re: AARRGGHHH!!! why doesn't this work?

    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
    [url]www.lonhosford.com[/url]
    May many happy bits flow your way!
    "adamsimms" <webforumsusermacromedia.com> wrote in message
    news:dpjhkn$aqa$1forums.macromedia.com...
    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


    Motion Maker Guest

  5. #5

    Default Re: AARRGGHHH!!! why doesn't this work?

    I did post the XML file in the previous message. It is right under the code if
    you look hard. when I p 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

    adamsimms Guest

  6. #6

    Default Re: AARRGGHHH!!! why doesn't this work?

    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.node Value); // 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
    [url]www.lonhosford.com[/url]
    May many happy bits flow your way!
    "adamsimms" <webforumsusermacromedia.com> wrote in message
    news:dpjkdi$els$1forums.macromedia.com...
    I did post the XML file in the previous message. It is right under the code
    if
    you look hard. when I p 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


    Motion Maker Guest

  7. #7

    Default Re: AARRGGHHH!!! why doesn't this work?

    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

    adamsimms Guest

  8. #8

    Default Re: AARRGGHHH!!! why doesn't this work?

    Glad to help!

    --
    Lon Hosford
    [url]www.lonhosford.com[/url]
    May many happy bits flow your way!
    "adamsimms" <webforumsusermacromedia.com> wrote in message
    news:dpk7k2$9sl$1forums.macromedia.com...
    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


    Motion Maker Guest

Similar Threads

  1. Doesn't work on the web
    By vistus in forum Coldfusion Flash Integration
    Replies: 1
    Last Post: July 1st, 08:43 AM
  2. Why doesn't this work??
    By kimber13 in forum Dreamweaver AppDev
    Replies: 0
    Last Post: February 23rd, 08:45 PM
  3. why doesn't this work?
    By jend in forum PHP Development
    Replies: 13
    Last Post: August 22nd, 08:27 PM
  4. Help w/ SQL doesn't work
    By Rob in forum Microsoft SQL / MS SQL Server
    Replies: 3
    Last Post: July 4th, 12:36 AM
  5. why this doesn't work (tm)? :)
    By Matija Papec in forum PERL Miscellaneous
    Replies: 2
    Last Post: June 26th, 11:36 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139