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:

    <collisionMovieData>
      <!-- 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. -->
      <circles>
        <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" />
      </circles>
    </collisionMovieData>
  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 "DrawingMethods.as"
    #include "MovieClip.as"
    #include "TextField.as"
    #include "Table.as"
    
    function loadData (  ) {
                           var myXML = new XML(  );
                           myXML.ignoreWhite = true; // Load the XML ...

Get Actionscript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.