Stage Five

The final stage in this application is to use an XML file to load initialization data. Up to this point, we have hardcoded the number of circles as well as their properties (color, radius, and velocity) into the Flash document. However, you can create an XML document from which you can load all that data at runtime so that you can make changes to the movie without having to reexport the .swf file. Here are the steps you should complete to finish the fifth stage of the application:

  1. Open a new text document and save it as circles.xml in the same directory as where you are saving your Flash documents.

  2. Add the following content to your XML document and save it:

      <!-- Define the dimensions of the rectangle within which circles can move. -->
      <bounceArea width="200" height="200" />
      <!-- Define the circles that should be created. In this example you create four
           circles with random velocities and colors and with various radii. -->
        <circle radius="30" vel="random" col="random" />
        <circle radius="5" vel="random" col="random" />
        <circle radius="24" vel="random" col="random" />
        <circle radius="10" vel="random" col="random" />
  3. Open stage4.fla and save it as stage5.fla.

  4. Modify the code on the main timeline, as shown here (changes are in bold):

    #include ""
    #include ""
    #include ""
    #include ""
    function loadData (  ) {
                           var myXML = new XML(  );
                           myXML.ignoreWhite = true; // Load the XML ...

Get Actionscript Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.