A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [RESOLVED] AS2 code importing formated xml

  1. #1
    Member
    Join Date
    Apr 2007
    Posts
    56

    resolved [RESOLVED] AS2 code importing formated xml

    XML image and text loading

    --------------------------------------------------------------------------------

    This is AS2, I am loading text and images with an XML file. Here is my XML:

    <data>
    <title name="Washington">

    <date><![CDATA[<b>Primary Election | </b>August 17th]]></date>
    <incumbent><![CDATA[<b>Incombent | </b>names]]></incumbent>
    <challenger><![CDATA[<b>GOP primarycandidates | </b>names]]></challenger>
    <O8result><![CDATA[<b>2008 Presidential Result | </b>Obama 58%, McCain 40%]]></O8result>
    <partyreg><![CDATA[<b>Party Registration | </b>None]]></partyreg>
    <pop55><![CDATA[<b>55+ Population | </b>19.6 %]]></pop55>
    <overview><![CDATA[<p><b>Overview | </b>Intro<b>Key 50+ Issues | </b>Issues.</p>]]></overview>
    <head01>heads/wa01.jpg</head01>
    <head02>heads/wa02.jpg</head02>
    <head03>heads/wa03.jpg</head03>
    <head04>heads/wa04.jpg</head04>
    <head05>heads/wa05.jpg</head05>
    </title>

    Here is my AS XML Load, just can't seem to get the sytax right. As you can see in the main MC mc_allstates I load the nodes for the "heads" into empty movie clips but not sure about my syntax.

    myXML.onLoad = function(succes){
    if(succes){
    trace (state_no);
    var root = this.firstChild;
    nodes = root.childNodes;
    myXML.firstChild.firstChild.isCDATA = true;
    mc_allstates.Title_txt.htmlText = nodes[state_no].attributes.name;
    subnodes = nodes[state_no].childNodes;
    mc_allstates.date_txt.htmlText = subnodes[0].firstChild.nodeValue;
    mc_allstates.incumbent_txt.htmlText = subnodes[1].firstChild.nodeValue;
    mc_allstates.challenger_txt.htmlText = subnodes[2].firstChild.nodeValue;
    mc_allstates.O8result_txt.htmlText = subnodes[3].firstChild.nodeValue;
    mc_allstates.partyreg_txt.htmlText = subnodes[4].firstChild.nodeValue;
    mc_allstates.pop55_txt.htmlText = subnodes[5].firstChild.nodeValue;
    mc_allstates.overview_txt.htmlText = subnodes[6].firstChild.nodeValue;
    mc_allstates.head01_mc.loadMovie = subnodes[7].firstChild.nodeValue;
    mc_allstates.head02_mc.loadMovie = subnodes[8].firstChild.nodeValue;
    mc_allstates.head03_mc.loadMovie = subnodes[9].firstChild.nodeValue;
    mc_allstates.head04_mc.loadMovie = subnodes[10].firstChild.nodeValue;
    mc_allstates.head05_mc.loadMovie = subnodes[11].firstChild.nodeValue;

    } else trace("Error loading XML document")

    All the CDATA text loads work fine but I am sure I have the sytax wrong on the image loads.
    Last edited by AVaughn; 08-22-2010 at 09:17 AM.

  2. #2
    Member
    Join Date
    Apr 2007
    Posts
    56

    Solved it myself ..... DAH!!! looking at this too long!

    Doessn't really make sence but This works:

    myXML.onLoad = function(succes){
    if(succes){
    trace (state_no);
    var root = this.firstChild;
    nodes = root.childNodes;
    myXML.firstChild.firstChild.isCDATA = true;
    this.createEmptyMovieClip("head01",43,-45);
    mc_allstates.Title_txt.htmlText = nodes[state_no].attributes.name;
    subnodes = nodes[state_no].childNodes;
    mc_allstates.date_txt.htmlText = subnodes[0].firstChild.nodeValue;
    mc_allstates.incumbent_txt.htmlText = subnodes[1].firstChild.nodeValue;
    mc_allstates.challenger_txt.htmlText = subnodes[2].firstChild.nodeValue;
    mc_allstates.O8result_txt.htmlText = subnodes[3].firstChild.nodeValue;
    mc_allstates.partyreg_txt.htmlText = subnodes[4].firstChild.nodeValue;
    mc_allstates.pop55_txt.htmlText = subnodes[5].firstChild.nodeValue;
    mc_allstates.overview_txt.htmlText = subnodes[6].firstChild.nodeValue;
    mc_allstates.head01_mc.loadMovie(subnodes[7].firstChild.toString());
    mc_allstates.head02_mc.loadMovie(subnodes[8].firstChild.toString());
    mc_allstates.head03_mc.loadMovie(subnodes[8].firstChild.toString());
    mc_allstates.head04_mc.loadMovie(subnodes[8].firstChild.toString());
    mc_allstates.head05_mc.loadMovie(subnodes[8].firstChild.toString());

    } else trace("Error loading XML document")

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