Chapter 1. Flex and ActionScript BASICS (evergreen)
A flex application consists of code in the following languages: ActionScript and mxml. From 3.0 onwards, actionscript has evolved from a prototype-based scripting language to a fully object-oriented scripting language that complies with the ecmascript standard. Mxml is a markup language, which is very similar to HTML and XML ).
How can we associate mxml with ActionScript? For the compiler, the two syntaxes are parsed and eventually translated into the same object. For example:
<Mx: button id = "BTN" label = "my button" Height = "100"/>
And
VaR BTN: button = new button ();
BTN. Label = "my button ";
BTN. Height = 100;
The same object is generated, and the main difference between the two is that the object created by ActionScript (the second example above) has nothing except the button, the object created in mxml adds the button to any component that contains the mxml code. The flex Framework calls the constructor Based on the object description in mxml and adds it to the parent object or sets it as an attribute of the parent object.
The <mx: SCRIPT> label can be used in the mxml file to contain ActionScript. However, the <mx: SCRIPT> label cannot be included in mxml. You can understand that mxml is used to describe the appearance and components of an application, while ActionScript is used to describe how to handle events and custom logic of an application. Although this is not completely accurate, however, you can understand the general relationship between the two. In some aspects, such as loops, function definitions, and conditional statements, all of them must be implemented through ActionScript. Apart from the simplest program that may not require ActionScript, most of them require mxml and ActionScript to collaborate with each other.
Most of the content discussed in this chapter is about the interaction between mxml and ActionScript: Use mxml to create components, create classes, add event listeners, write the codes of ActionScript and mxml, and create function declarations, although not all the content is listed, these are the basic content of ActionScript and mxml.
Section 1.1. Use flex builder to create a flex Project
1.1.1. Problem
I want to create a flex project using Flex builder.
1.1.2. Solution
Use the create new Project Wizard
1.1.3. Discussion
Built on Eclipse, flex builder is a very good interactive development environment (IDE) and a very popular Java development tool. Although flex builder is not required to develop flex programs, flex Builder provides many excellent features to help you effectively improve design and development efficiency. Flex builder can be installed independently or as an Eclipse plug-in.
For developers, the first thing is how to create a flex project. The flex Project is a little different from other projects because it needs to contain SWC (Flex Library) Flex library SWC (unlike the ActionScript Project) compiled SWF files that can be executed by flash players (unlike the flex Library Project ). To create a project, right-click the flex navigator view and select newflex project from the shortcut menu. The Create Project dialog box is displayed.
Figure 1-1. Create a new Flex Project
Figure 1-2. Use flex builder to create a new project
Enter the project name and storage path of the project, which are stored in C:/Documents and Settings/username/documents/workspace/projectname by default in Windows, by default, MAC systems are stored in users, username, documents, workspace, and projectname. Of course, you can change it and store it in your favorite location. The project name must be unique and cannot be repeated. For the project type, you can select a web program or a desktop program (Air Program). Finally, select the desired server technology for data interaction.
After setting, click Finish to set the SWF output directory path and click Next.
Figure 1-3. Set the region attribute of the output SWF File
After setting the SWF output path, you also need to set the path of the source file storage directory or the SWC library file. You can add other directories to the Source Path label and add the SWC file to the library path label. In this dialog box, you can also change the file name of the main mxml program, which is the same as the project name by default.
Figure 1-4. Set the source file directory and main program file name
Figure 1-5. set other required Libraries
After setting the path, click Finish. After the project is created, you can start development.