A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Help with importing <link> from xml

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    2

    Help with importing <link> from xml

    Hi all. First of all, please excuse me my english.

    I´m having a hard time trying to import de <link> from an XML.
    My xml looks something like this

    <?xml version="1.0"?>
    <select project="xmldata" date="11/20/2004">
    <object negrita="Something Her "header="Something else here"><link>document.pdf</link></object>

    I´m ok with the two variables, but not having succes importing the link to the button.
    I´m working with addchild
    Here´s the actionscript

    importXML = new XML();
    importXML.ignoreWhite = true;
    importXML.onLoad = function(success)
    {
    if (success)
    {
    var depth = 0;
    var nextY = 10;
    count = 0;
    var root = this.firstChild;
    // The root node
    var attr = root.attributes;
    for (var i = root.firstChild; i != null; i = i.nextSibling)
    {
    tempMC = attachMovie("box", "box"+count, depth++, {_ynextY), _x-200)});
    nextY += tempMC._height + 2;
    tempMC.name_txt.text = i.attributes.header;
    tempMC.negrita_txt.text = i.attributes.negrita;
    count ++;
    }
    }
    }
    importXML.load(data.xml);


    In the movieclip "box" there is a button with the action:
    on ( release )
    {
    getURL(link);
    }
    Last edited by 7incho; 09-17-2010 at 12:54 AM.

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    some suggestions.. dont use ROOT as a var..

    to 'me' it seemed your XML was 'off'

    <select project="xmldata" date="11/20/2004">

    should be:

    <select project="xmldata" date="11/20/2004" />

    unless you didnt post the full XML schema/data


    loading the xml should be a string value:

    importXML.load("data.xml");

  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    2
    Thx whispers.
    Finally i solved this issue but then I found one bigger.
    There is a huge incompatibility between flash proyector and linking to pdf.
    I know that I can link to a bat file, but the problem was that i have 650 pdf.
    I end up opening pdf files in the explorer.
    Not happy with the result, but works. Anyway, i´ll stick to webdesing. My experience developing a cd wasn´t a happy one.

    Thanks for your generous answer!

  4. #4
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    oh..you got it solved..nice.


    I was going to post an alternative solution to working with XML..

    but you got it all fixed.

    here it is anyways..

    AS 2.0:
    actionscript Code:
    importXML = new XML();
    importXML.ignoreWhite = true;
    importXML.onLoad = function(success) {
        if (!success) {
            trace("XML failed to load");
        } else {
            trace("XML LOADED");
           
            //firstNode
            var firstNode = this.childNodes[0];
            //attributes
            var xProj = firstNode.attributes.project;
            var xDate = firstNode.attributes.date;
           
            //secondNode [objects]
            var secondNode = this.childNodes[1];
            var totalObjects = secondNode.childNodes.length;
            //trace(newline+"TOTAL OBJECTS: "+totalObjects);
           
            for (i=0;  i<totalObjects; i++) {  
                var negrita = secondNode.childNodes[i].attributes.negrita;
                var header = secondNode.childNodes[i].attributes.header;
                trace(newline+"Object Header "+(i+1)+": "+header);
               
                var totalLinks = secondNode.childNodes[i].childNodes.length;
                trace("TOTAL LINKS: "+totalLinks);
                for (s=0;  s<totalLinks; s++) {        
                    var link = secondNode.childNodes[i].childNodes[s].firstChild;
                    trace("LINK: "+link);
                }
            }
        }
    };
    importXML.load("data.xml");


    the XML:

    PHP Code:
    <?xml version="1.0"?>

    <select project="xmldata" date="11/20/2004" />


    <objects>
        <object negrita="Something Here 1-1" header="Something else here  1-1">
            <link>document1-1.pdf</link>
            <link>document1-2.pdf</link>
            <link>document1-3.pdf</link>
        </object>

        <object negrita="Something Here 2-2" header="Something else here 2-2">
            <link>document2-1.pdf</link>
            <link>document2-3.pdf</link>
        </object>

    </objects>

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