dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: displaying XML data?

  1. #1
    Member
    Join Date
    Nov 2000
    Location
    Hollywood, FL
    Posts
    41

    displaying XML data?

    im working on a .swf that has to pull data from an .xml file, and display it...

    Ive been struggling with this, thanks for taking a look

    the source .fla is at www.mikehalak.com/new.fla
    the actionscript at the root of the movie is:

    var portfolioXML:XML = new XML();
    content_display = "Loading data...";
    portfolioXML.onLoad=init;
    portfolioXML.load("portfolio_list.xml");

    //parse script
    function init(){
    if(this.loaded) {
    content_display = "Data loaded.";
    }
    //main node xml object
    mainNode = portfolioXML.firstChild;
    //main node name ( 'DDGportfolio' in xml file)
    mainName=mainNode.nodeName;

    theString=mainName+"\r\r";

    //ARRAY of Children in Main(CATEGORIES in xml file)
    childrenOfMain=new Array();
    childrenOfMain= mainNode.childNodes;

    for(i=0;i<=childrenOfMain.length;i++){
    if(childrenOfMain[i].nodeName<>null){
    //name of this child (portfolioitem in XMl file);
    theString=theString+"\r"+childrenOfMain[i].nodeName+"=";
    //this child's xml:
    thisChild = childrenOfMain[i];
    //array nodes of in this child ( filename, description, category ):
    nodesOfThisChild = thisChild.childNodes;
    for(j=0;j<=childrenOfMain.length;j++){
    //this tags xml
    thisTag = nodesOfThisChild[j];
    //this tags name
    thisName = thisTag.nodeName;
    if(thisTag.nodeName<>null){
    // and tags value:
    thisValue=thisTag.firstChild.nodeValue;
    theString=theString+thisName+":"+thisValue+" ";
    }//if
    }//for
    }//if
    }//for
    }//end init
    _root.show = portfolioXML.firstChild;
    // i put this in to try to display a value from xml, but it returned null...



    the xml file below is at www.mikehalak.com/portfolio_list.xml

    <?xml version="1.0" encoding="iso-8859-1"?>
    <DDGportfolio>
    <portfolioitem id="0" name="websitedesign item 1">
    <filename>portfolio/category1_test1.swf</filename>
    <description>This is a description of the project C1T1</description>
    <category name="websitedesign" id="0">websitedesign</category>
    </portfolioitem>
    <portfolioitem id="1" name="websitedesign item 2">
    <filename>portfolio/category1_test2.swf</filename>
    <description>This is a description of the project C1T2</description>
    <category name="websitedesign" id="0">websitedesign</category>
    </portfolioitem>
    <portfolioitem id="2" name="websitedesign item 3">
    <filename>portfolio/category1_test3.swf</filename>
    <description>This is a description of the project C1T3</description>
    <category name="websitedesign" id="0">websitedesign</category>
    </portfolioitem>
    <portfolioitem id="3" name="websitedesign item 4">
    <filename>portfolio/category1_test4.swf</filename>
    <description>This is a description of the project C1T4</description>
    <category name="websitedesign" id="0">websitedesign</category>
    </portfolioitem>
    <portfolioitem id="0" name="flashbanners item 1">
    <filename>portfolio/category2_test1.swf</filename>
    <description>This is a description of the project C2T1</description>
    <category name="flashbanners" id="1">flashbanners</category>
    </portfolioitem>
    <portfolioitem id="1" name="flashbanners item 2">
    <filename>portfolio/category2_test2.swf</filename>
    <description>This is a description of the project C2T2</description>
    <category name="flashbanners" id="1">flashbanners</category>
    </portfolioitem>
    <portfolioitem id="2" name="flashbanners item 3">
    <filename>portfolio/category2_test3.swf</filename>
    <description>This is a description of the project C2T3</description>
    <category name="flashbanners" id="1">flashbanners</category>
    </portfolioitem>
    <portfolioitem id="3" name="flashbanners item 4">
    <filename>portfolio/category2_test4.swf</filename>
    <description>This is a description of the project C2T4</description>
    <category name="flashbanners" id="1">flashbanners</category>
    </portfolioitem>
    <portfolioitem id="0" name="emailCreatives item 1">
    <filename>portfolio/category3_test1.swf</filename>
    <description>This is a description of the project C3T1</description>
    <category name="emailCreatives" id="2">emailCreatives</category>
    </portfolioitem>
    <portfolioitem id="1" name="emailCreatives item 2">
    <filename>portfolio/category3_test2.swf</filename>
    <description>This is a description of the project C3T2</description>
    <category name="emailCreatives" id="2">emailCreatives</category>
    </portfolioitem>
    <portfolioitem id="2" name="emailCreatives item 3">
    <filename>portfolio/category3_test3.swf</filename>
    <description>This is a description of the project C3T3</description>
    <category name="emailCreatives" id="2">emailCreatives</category>
    </portfolioitem>
    <portfolioitem id="3" name="emailCreatives item 4">
    <filename>portfolio/category3_test4.swf</filename>
    <description>This is a description of the project C3T4</description>
    <category name="emailCreatives" id="2">emailCreatives</category>
    </portfolioitem>
    <portfolioitem id="0" name="Landing Page item 1">
    <filename>portfolio/category4_test1.swf</filename>
    <description>This is a description of the project C3T1</description>
    <category name="landingPages" id="3">landingPages</category>
    </portfolioitem>
    <portfolioitem id="1" name="Landing Page item 2">
    <filename>portfolio/category4_test2.swf</filename>
    <description>This is a description of the project C3T2</description>
    <category name="landingPages" id="3">landingPages</category>
    </portfolioitem>
    <portfolioitem id="2" name="Landing Page item 3">
    <filename>portfolio/category4_test3.swf</filename>
    <description>This is a description of the project C3T3</description>
    <category name="landingPages" id="3">landingPages</category>
    </portfolioitem>
    <portfolioitem id="3" name="Landing Page item 4">
    <filename>portfolio/category4_test4.swf</filename>
    <description>This is a description of the project C3T4</description>
    <category name="landingPages" id="3">landingPages</category>
    </portfolioitem>
    </DDGportfolio>
    Attached Files Attached Files

  2. #2
    Senior Member tupps's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne
    Posts
    2,035
    All of the code that does anything with the XML has to go into the init function. Once the init function has been called the Xml will be read and you can then read the data. Where your code is at the moment it will be run before the xml has been loaded.

    Also when you move your code into the init function you will need to replace references to portfolioXML with this.

    Thanks

    Luke
    Flash-XML FAQ
    http://www.tupps.com/flash/faq/

  3. #3
    Member
    Join Date
    Nov 2000
    Location
    Hollywood, FL
    Posts
    41
    thanks tupps!
    www.mikehalak.com

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