A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Loading XML

  1. #1
    Senior Member Flamboyant Flasher's Avatar
    Join Date
    Dec 2001
    Posts
    1,253

    Loading XML

    First I'm trying to get this XML file to load, but it's coming up undefined. Here's the actionscript:


    var MyX:XML=new XML();
    MyX.ignoreWhite=true;

    var urls:Array=new Array();
    var captions:Array=new Array();

    MyX.onLoad=function(){
    var photos:Array=this.firstChild.childNodes;


    for(i=0;i<photos.length;i++){
    urls.push(photos[i].attributes.url);
    captions.push(photos[i].attributes.caption);
    }
    }

    holder.loadMovie(urls[0]);
    caption.text =captions[0];

    MyX.load("funky.xml");


    Now, here's the XML file:


    <?xml version="1.0" encoding="iso-8859-1"?>

    <slideshow>
    <photo url="m51.jpg" caption="M5 power, untouchable" />
    </slideshow>

    I have a movieclip and text field on the stage with the instance names "holder" and "caption" respecively.

  2. #2
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    You're trying to load the array items before the data is all pushed in. Tuck it back one bracket so it's done after the loop pushes all the items


    var MyX:XML=new XML();
    MyX.ignoreWhite=true;

    var urls:Array=new Array();
    var captions:Array=new Array();

    MyX.onLoad=function(){
    var photos:Array=this.firstChild.childNodes;


    for(i=0;i<photos.length;i++){
    urls.push(photos[i].attributes.url);
    captions.push(photos[i].attributes.caption);
    }
    holder.loadMovie(urls[0]);
    caption.text =captions[0];
    }


    MyX.load("funky.xml");

  3. #3
    Senior Member Flamboyant Flasher's Avatar
    Join Date
    Dec 2001
    Posts
    1,253
    I fixed it; it's loading well now...


    Howeve,r when I insert my CDATA tags , it's coming back undefined..

    Here is the CDATAtags:



    <?xml version="1.0" encoding="iso-8859-1"?>

    <slideshow>
    <photo url="m51.jpg" caption="The m5 is the meanest Sedan in the world, check out the <![CDATA[<a href='http://www.bmwusa.com'>M5 Power.</a>]]>
    " />
    </slideshow>


    I made the textfield "caption" HTML enabled; still coming back undefined... the CDATA issue is the problem now...

  4. #4

  5. #5
    Senior Member Flamboyant Flasher's Avatar
    Join Date
    Dec 2001
    Posts
    1,253
    I'm not familiar with element style. Can you provide an example or a working fla? I just need hyperlinks to work in XML files...

    It is my view that hyperlinks in XML files that would be loaded into Flash needs some attention in the Flash community because msot people, even advanced scripters that I know, doesn't know the simple or standard way to insert hyperlinks in xml. Doesn't Flash 8 has a need and improved XML parser?

  6. #6
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    Well, it depends on the delivery. I can, for instance send in a url without CDATA from the XML and use it for a hyperlink on the frontend. What you are doing is sending in html with the hyperlink coded as html...in this case the methods have always been the same and once you are used to using CDATA, it's something you will always rely on for the purpose. Even with AS3 and Flex 2/Flash 9 it's used when sending in html formatted strings.

    I'll contact you back with an example when I get home

  7. #7
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    Using this style of XML:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <items>
    <slideshow>
    <pic>image15.jpg</pic>
    <caption><![CDATA[<a href='http://www.bmwusa.com'>M5 Power</a>]]></caption>
    </slideshow>
    </items>

    And this AS:

    var MyX:XML=new XML();
    MyX.ignoreWhite=true;

    var urls:Array=new Array();
    var captions:Array=new Array();

    MyX.onLoad=function(){
    var photos:Array=this.firstChild.childNodes;


    for(i=0;i<photos.length;i++){

    urls.push(photos[i].childNodes[0].firstChild.nodeValue);
    captions.push(photos[i].childNodes[1].firstChild.nodeValue);
    }
    holder.loadMovie(urls[0]);
    caption.htmlText =captions[0];
    }


    MyX.load("funky.xml");


    You'll be cruisin

  8. #8
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    I see you've bumped into another thread asking the same thing I just posted scripting for so I'll close this one.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center