How to Load a Flash Movie From XML Flash Code

How to Load a Flash Movie From XML Flash Code thumbnail
Loading a Flash movie from XML is easy with a little know-how.

ActionScript, the scripting language built into Adobe Flash, includes support for processing XML, making it easy to manage things like RSS (Really Simple Syndication) feeds in your Flash movies. Another useful XML trick is to store assets like images or other Flash movies as separate files and load them from an XML file when the user selects them. This helps reduce the size of your main Flash movie file, making viewing easier for your users. With some extra effort, you can maintain a list of Flash movies from which your website visitors can select.

Things You'll Need

  • Adobe Flash CS3 or later
  • ActionScript 3
Show More

Instructions

    • 1

      Create the Flash movie you plan to load and save it to your working directory.

    • 2

      Create an XML file and add markup that references the location of the Flash movie you just created. The XML should look something like:
      <myMovie>
      <movieURL>working_directory/myMovie.swf</movieURL>
      </myMovie>

    • 3

      Create the main Flash movie and drag a UILoader onto the stage. Give your UILoader an instance name, like xmlLoader.

    • 4

      Add an ActionScript layer and create a new URLLoader variable:
      var XMLURLLoader:URLLoader = new URLLoader();

    • 5

      Load your variable with the content from your XML file.
      XMLURLLoader.load(new URLRequest("movie.xml"));

    • 6

      Add an event listener that calls a function to process the XML file:
      XMLURLLoader.addEventListener(Event.COMPLETE, processXML);

    • 7

      Write a function to process the XML file
      function processXML(event:Event):void {
      var theXMLData:XML=new XML(XMLURLLoader.data);
      xmlLoader.text = theXMLData.movieURL[0]; }

    • 8

      Test your movie.

Tips & Warnings

  • Add a trace statement to your function to view the results of loading XML into your variable.

  • Use arrays to store other descriptive elements such as a title and description. You can also use an array to store multiple instances of the <myMovie> element.

Related Searches:

References

Resources

  • Photo Credit Flag of movie image by Yuriy Panyukov from Fotolia.com

Comments

You May Also Like

Related Ads

Featured