This Season
 

How to Load an External XML File for an SWF File

Originally dubbed the Small Web Format, SWF is the standard file format used in Adobe Flash. To load an external XML file in Flash, Adobe provides a scripting language called ActionScript, which is a variation of standard ECMAScript. The process, then, is to write an ActionScript in Flash that opens the XML file and passes the result to the SWF application.

Related Searches:
    Difficulty:
    Moderately Challenging

    Instructions

    Things You'll Need

    • Adobe Flash CS4 or another ActionScript editor
    • Flash-enabled Web browser
      • 1

        Create a new Flash file and open a new ActionScript from the timeline.

      • 2

        Create the following variables:
        var gallery_xml:XML;
        var xmlReq:URLRequest = new

      • 3

        Create a URL request to open the XML file. For example, the following opens the public timeline at Twitter:
        URLRequest("http://twitter.com/statuses/public_timeline.xml");
        var xmlLoader:URLLoader = new URLLoader();

      • 4

        Create a function to load the resulting XML and display its content within the Flash application:

        function xmlLoaded(event:Event):void
        {
        gallery_xml = new XML(xmlLoader.data);
        info_txt.text = gallery_xml.toXMLString();
        }

      • 5

        Load the XML object and add an event listener that calls your function:
        xmlLoader.load(xmlReq);
        xmlLoader.addEventListener(Event.COMPLETE,xmlLoaded);

      • 6

        Test your ActionScript:

    Tips & Warnings

    • If you receive errors, ensure that your XML document is valid and well formed.

    • This method has been tested in Flash CS4. Previous versions of Flash may not support the XML loaders.

    • The URL for Twitter's public timeline may change. Verify the URL before you attempt this example, or supply another XML file in the URLRequest().

    Related Searches

    References

    Resources

    Read Next:

    Comments

    You May Also Like

    Follow eHow

    Related Ads