Detailed instructions for use are in the User's Guide.
[. . . ] Getting Started with Flex
Trademarks ActiveEdit, ActiveTest, Add Life to the Web, Afterburner, Aftershock, Andromedia, Allaire, Animation PowerPack, Aria, Attain, Authorware, Authorware Star, Backstage, Blue Sky Software, Blue Sky, Breeze, Bright Tiger, Captivate, Clustercats, ColdFusion, Contents Tab Composer, Contribute, Design In Motion, Director, Dream Templates, Dreamweaver, Drumbeat 2000, EDJE, EJIPT, Extreme 3D, Fireworks, Flash, FlashHelp, Flash Lite, FlashPaper, Flex, Flex Builder, Fontographer, FreeHand, Generator, Help To Source, HomeSite, Hotspot Studio, HTML Help Studio, JFusion, JRun, Kawa, Know Your Site, Knowledge Objects, Knowledge Stream, Knowledge Track, LikeMinds, Lingo, Live Effects, MacRecorder Logo and Design, Macromedia, Macromedia Action!, Macromedia Central, Macromedia Flash, Macromedia M Logo and Design, Macromedia Spectra, Macromedia xRes Logo and Design, MacroModel, Made with Macromedia, Made with Macromedia Logo and Design, MAGIC Logo and Design, Mediamaker, Movie Critic, Open Sesame!, RoboDemo, RoboEngine JFusion, RoboHelp, RoboHelp Office, RoboInfo, RoboInsight, RoboPDF, 1-Step RoboPDF, RoboFlash, RoboLinker, RoboScreenCapture, ReSize, Roundtrip, Roundtrip HTML, Shockwave, Sitespring, Smart Publishing Wizard, Software Video Camera, SoundEdit, Titlemaker, UltraDev, Web Design 101, what the web can be, WinHelp, WinHelp 2000, WinHelp BugHunter, WinHelp Find+, WinHelp Graphics Locator, WinHelp Hyperviewer, WinHelp Inspector, and Xtra are either registered trademarks or trademarks of Macromedia, Inc. and may be registered in the United States or in other jurisdictions including internationally. Other product names, logos, designs, titles, words, or phrases mentioned within this publication may be trademarks, service marks, or trade names of Macromedia, Inc. or other entities and may be registered in certain jurisdictions including internationally. [. . . ] Including ActionScript files Flex lets you point to external ActionScript files in your <mx:Script> tags. At compile-time, the compiler copies the entire contents of the file into your MXML application. As with ActionScript in an <mx:Script> block, ActionScript in included files must be variable declarations or in functions. You cannot define classes in included files. Variables and functions defined in an included ActionScript file are available to any component in the MXML file. An included ActionScript file is not the same as an imported ActionScript class. Flex provides access to the included file's variables and functions, but does not add a new class, since the MXML file itself is a class.
48
Chapter 3: Using ActionScript
Included ActionScript files do not need to be in the same directory as the MXML file. However, you should organize your ActionScript files in a logical directory structure. Flex detects changes in ActionScript files using timestamps. If the file has changed since the last request, Flex regenerates the application before responding to the client. If you change the ActionScript in one of the imported ActionScript files, the next time the application is requested, the changes appear. There are two ways to include an external ActionScript file in your Flex application:
· The source attribute of the <mx:Script> tag. This is the preferred method for including
external ActionScript class files.
· The #include directive inside <mx:Script> blocks.
The following sections describe these two methods of including an external ActionScript file. Using the source attribute You use the source attribute of the <mx:Script> tag to include external ActionScript files in your Flex applications. This provides a way to make your MXML files less cluttered and promotes code reuse across different applications. The following example shows the contents of the IncludedFile. as file:
public function computeSum(a:Number, b:Number):Number { return a + b; }
The following example imports the contents of the IncludedFile. as file. This file is located in the same directory as the MXML file.
<?xml version="1. 0"?> <mx:Application xmlns:mx="http://www. macromedia. com/2003/mxml"> <mx:Script source="IncludedFile. as" /> <mx:TextInput id="ta1st" text="3"/> <mx:TextInput id="ta2nd" text="3"/> <mx:TextArea id="taMain"/> <mx:Button id="b1" label="Compute Sum" click="taMain. text=computeSum(Number(ta1st. text), Number(ta2nd. text))"/> </mx:Application>
The source attribute of the <mx:Script> tag supports both relative and absolute paths. For more information, see "Referring to external files" on page 51. You cannot use the source attribute and wrap ActionScript code inside the same <mx:Script> tag. To include a file and write ActionScript in the MXML file, use two <mx:Script> tags.
Using ActionScript in Flex applications
49
Using the #include directive The #include directive is an ActionScript statement that copies the contents of the specified file into your MXML file. The #include directive uses the following syntax:
#include "file_name"
The following example includes the myfunctions. as file:
<mx:Script> <![CDATA[ #include "myfunctions. as" . . . ]]> </mx:Script> Note: The #include directive is a special kind of ActionScript statement. [. . . ] For more information, see Chapter 20, "Using Styles and Fonts, " in Developing Flex Applications.
Data validation
Data formatting
Cursor management
History management
Drag-and-drop management
ToolTips
Styles, fonts, and themes
80
Chapter 4: Architecting Flex Applications
Feature Behaviors
Description Behaviors let you add animation or sound to applications in response to user or programmatic action. For more information, see Chapter 21, "Using Behaviors, " in Developing Flex Applications. Repeaters let you dynamically repeat any number of controls or containers specified in MXML tags, at runtime. For more information, see Chapter 8, "Dynamically Repeating Controls and Containers, " in Developing Flex Applications.
Repeaters
Image and media importing You can use MXML tags to import several images into applications. [. . . ]