
Page 1 of 2 In May 2009, Wrox released a ground-breaking book: Professional Adobe Flex 3, written by Joseph Balderson, Peter Ent, Jun Heider, Todd Prekaski, Tom Sugden, Andrew Trice, David Hassoun and Joe Berkovitz, (ISBN 0470223642). This landmark publication consists over 1400+ pages of Flex reference material, covering a multitude of topics ranging from beginner to advanced, from the fundamentals of the Flash Platform technology ecosystem to the intricacies of the most advanced Flex-related frameworks and server products, in a breadth and depth found nowhere else.
In a Community MX exclusive, the following is an excerpt from Chapter 6: Using Flex Builder 3. In this tutorial you will build a simple ActionScript application, and learn all about the undocumented [SWF] metadata tag to configure the Flash Player publishing properties.

In this exercise, you're going to learn a bit more about Flex Builder 3 by creating an ActionScript application in Source mode.
Most of the time you spend in Flex Builder will probably be creating code in Source mode, using Design mode only for quick mockups or prototypes, or to check the layout of certain UI.
Creating an ActionScript project means that using the Flex framework is optional, and must be explicitly imported for the application to be compiled with the Flex framework. This means you can, if you wish, create SWF applications with a small file size footprint that depend solely on the ActionScript 3.0 and Flash API classes.

Figure 6-17

Figure 6-18
As shown in Figure 6-19, you should now see the project in the Flex Navigator View, and the DrawCircles.as file loaded in the editor containing the following default code:
package {
import flash.display.Sprite;
public class DrawCircles extends Sprite
{
public function DrawCircles()
{
}
}
}
Notice that DrawCircles extends Sprite by default and not a Flex framework class. By default the editor defaults to the Source Mode Editor, since you can only use Design mode when working on an MXML file.
Notice that the Outline View now displays the default class structure for the DrawCircles class you just created.

Figure 6-19
package {
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
public class DrawCircles extends Sprite
{
public function DrawCircles()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
doDrawCircle( 0x336699 );
doDrawCircle( 0x993333 );
doDrawCircle( 0x339933 );
}
private function doDrawCircle( color:uint ):void
{
var child:Shape = new Shape();
child.graphics.beginFill( color );
child.graphics.lineStyle( 2, 0xCCCCCC );
child.graphics.drawCircle( 30, 40, 30);
child.graphics.endFill();
child.x = (this.numChildren * 65) + 10;
child.y = 0;
addChild(child);
}
}
}
Listing 6-1
The first two lines in the constructor function set the stage properties so that the SWF will appear at the top left and will be resized rather than scaled in the browser. The constructor then calls the doDrawCircle method, passing a hex color number for the new circle.
The doDrawCircle method uses the Flash drawing API (you could say the "Flash 6 Drawing API," not the new "Flash 10 Drawing API") to draw a gray circle with a fill, the color that has been passed to its argument. It then positions the new circle according to the current number of circles already created and adds the object to the stage with the addChild method.
See Chapter 8 for more information on using the code editor in Flex Builder.
Now let's compare file sizes between the two applications from this chapter.
This demonstrates just how much the Flex framework adds to a SWF file. If the file size of your SWF is a concern, such as the development of small embedded Flash widgets or online Flash advertising, it pays not to use the Flex framework. (Shhh! Don't tell anyone I told you that! This is a Flex book, after all!) For more information about the class APIs available without the Flex Framework, see Chapter 4, "Using ActionScript 3.0." For a review of where Flex fits into Flash platform development, see Chapter 1, "Why Flex?"
Keywords
Professional Flex 3, Flex, Flex 3, book, Wrox, excerpt, actionscript, swf metadata, flex builder