Skip to Content
Actionscript Cookbook
book

Actionscript Cookbook

by Joey Lott
July 2003
Intermediate to advanced
896 pages
45h 43m
English
O'Reilly Media, Inc.
Content preview from Actionscript Cookbook

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

ActionScript 3.0 Cookbook

ActionScript 3.0 Cookbook

Joey Lott, Darron Schall, Keith Peters
ActionScript 3.0 Design Patterns

ActionScript 3.0 Design Patterns

William Sanders, Chandima Cumaranatunge

Publisher Resources

ISBN: 0596004907Catalog PageErrata