A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: xml load into flash but only show selected text

  1. #1
    Senior Member green_eye's Avatar
    Join Date
    Apr 2004
    Location
    Sarasota, Florida
    Posts
    1,496

    xml load into flash but only show selected text

    XML File has 24 entries

    button1
    Heading
    Content
    URL to event

    button2
    Heading
    Content
    URL to Event
    .
    .
    .
    button24 ...

    When button1 is selected loads just what is in button1
    button2 loads button2 text and so on

    Will a single xml file work this way depending on what button is selected OR do I need to create 24 separate files?

  2. #2
    Spit
    Join Date
    Oct 2008
    Location
    Philly, PA
    Posts
    51
    A single XML file will work for this. Just set all the nodes you want with different names in the XML and have flash retrieve them and save them as variables or arrays. That way you can access them whenever you want once there loaded.

  3. #3
    Senior Member green_eye's Avatar
    Join Date
    Apr 2004
    Location
    Sarasota, Florida
    Posts
    1,496
    var advent_calender_xml = new XML();

    advent_calender_xml.onLoad = function(load_success) {
    if (load_success)

    { trace(advent_calender_xml.firstChild);
    }
    }
    advent_calender_xml.load('advent_calender.xml');


    This is the error:
    TypeError: Error #1006: value is not a function.at loader_xml_fla::MainTimeline/frame1()

  4. #4
    Spit
    Join Date
    Oct 2008
    Location
    Philly, PA
    Posts
    51
    This is the AS I use to connect to an XML file:

    Actionscript Code:
    // populates the text fields by callinging the functions
    // "getValue" and "findNode", if it finds the xml document

    function processXMLData (success) {
        if (success) {
            var rootNode = this.firstChild;

            // Text
            var text_1Node = findNode (rootNode, "text_1");
            _global.text_1_ = getValue (text_1Node);

            var text_2Node = findNode (rootNode, "text_2");
            _global.text_2_ = getValue (text_2Node);

            var text_3Node = findNode (rootNode, "text_3");
            _global.text_3_ = getValue (text_3Node);

            var text_4Node = findNode (rootNode, "text_4");
            _global.text_4_ = getValue (text_4Node);

        } else {
            trace ("No XML found");
        }
    }

    // functions that find and retrieve the data
    function getValue (node) {
        if (node && node.firstChild) {
            return node.firstChild.nodeValue;
        }
        return "";
    }

    function findNode (node, nodeName) {
        if (node.nodeName == nodeName) {
            return node;
        }
        for (var i = 0; node.childNodes && i < node.childNodes.length; i++) {
            var foundNode = findNode (node.childNodes[i], nodeName);
            if (foundNode != null) {
                return foundNode;
            }
        }
        return null;
    }

    // this pulls in the XML doc and sets it = to xmlData
    var xmlData = new XML ();
    xmlData.ignoreWhite = true;
    xmlData.onLoad = processXMLData;
    xmlData.load ("Name_Of_Your_XML_Document.xml");

    The functions are used for finding data and removing the node names so they don't get pushed into the text fields as well. By setting the nodes equal to global variables you can access them from anywhere in the swf. You'll also want to use CDATA in your XML doc. It allows you to detail your text with HTML settings.

    Hope this helps!

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