Flex 3.0

Flex programming languages

Flex 3 applications are written using two programming languages—ActionScript 3 and MXML:

ActionScript 3 is the most recent version of the ActionScript language to evolve in the Flash authoring environment over the lifetime of the product. A complete object-oriented language, ActionScript 3 is based on the ECMAScript edition 4 draft language specification. It includes most of the elements of object-oriented languages, including class definition syntax, class package structuring, strong data typing of variables, and class inheritance.

MXML versus ActionScript 3

MXML and ActionScript can be used interchangeably in many situations. MXML is commonly used to declare visual layout of an application and many objects, but it’s usually your choice as a developer as to when to use each language.

The Flex SDK and Flex Builder both compile source code in MXML and ActionScript, producing executable applications that are hosted by the Flash Player on the Web or the Adobe Integrated Runtime (“AIR”) on the desktop.

Declaring objects in MXML

The Label class is represented in MXML as a tag named . To create an instance of the Label class using MXML and set its text property to a value of Hello World, declare the tag and set the property as an XML attribute:

This results in creating an instance of the Label class that is displayed in the application.

Declaring objects in ActionScript 3

The Label class also can be instantiated using ActionScript 3. When using the ActionScript 3 coding model, you first create the object using the class’s constructor method and then add the object to the application’s display list so it becomes visible. You can set the text property anytime after creating the object:

import mx.controls.Label;
var myLabel:Label = new Label();
myLabel.text = “Hello World”;
this.addChild(myLabel);

Developing in Flash

As described above, developers who use Flash are frequently focused on presenting animation, hosting video, and the like. Flash is generally considered superior for animation work because of its use of a timeline to control presentations over a designated period of time. Flash upports a variety of animation techniques that make use of the timeline, including these:

 Frame by frame animation
 Motion tweening
 Shape tweening

Flash also allows you to create animations using pure ActionScript code, but that approach also can be used in Flex. Developers who come from a graphic design background and are used to thinking visually appreciate the precision and visual feedback that the Flash development environment provides.

One drawback that application developers encounter with Flash is that the primary source document used in Flash, the .fla file format, is binary. As a result, it doesn’t work well with the source control systems that application developers commonly use to manage their development projects, because you can’t easily “diff,” or discover differences between, different versions of a binary file.

Developing in Flex

Developers who use Flex to build their applications commonly have a background in some other programming language. Documents can be created and made useful in Flash without any programming, but a Flex application is almost entirely code-based. Animations are handled entirely through ActionScript, because Flex doesn’t have a timeline as part of its development toolkit.

Flex also has superior tools for handling large-scale applications that have dozens or hundreds of views, or screens. Although Flash CS3 has a screen document feature, this feature hasn’t received the development attention from Adobe that would make it a compelling architectural choice for these “enterprise” applications.

Finally, Flex applications are built in source code, which is stored in text files. These text files are easy to manage in source-code control applications such as CVS and Subversion. As a result, multideveloper teams who are dependent on these management tools find Flex development to be a natural fit to the way they already work.

The Flex Builder 3 design view feature has become more friendly and useful to graphic designers than in previous versions, but it isn’t always intuitive to a designer who’s used to “real” graphic design tools like Adobe’s own Photoshop, Illustrator, and Fireworks.