Flex is a architecture that provides development design and operational support that enables developers to create a "rich client Internet application/rich Internet Application/ria" that leverages flash Player 9 as a foreground, To meet the user's more intuitive and highly interactive online experience.
The typical steps for opening a flex application are as follows:
1. Select a series of predefined components (such as tables, buttons, etc.) for designing the application interface.
2, the layout of components to design the user interface
3. Use styles and themes to increase visual design
4, add dynamic behavior (such as the interaction between program parts)
5. Define the database services required for the connection
6. Compile the source code into a SWF file and run it in Flash Player.
A typical Flex application includes the following elements:
1. Flex Framework
Provides all the components needed to create an RIA: Containers for application layout planning, control over user interfaces and access to data from users, widely supported data binding, data formatting, and validation of valid values, and event-driven development patterns. The Flex framework is included in the Common Component library (SWC) file.
2, MXML
Each flex application contains at least one Mxml file, which is used as the main file for the program. Mxml is a markup language that is an xml-based implementation for creating Flex applications.
3, actionscriopt 3.0
Adding dynamic behavior to an application is an implementation based on ECMAScript, similar to JavaScript. It can be added as a script block directly in the Mxml file, or create a separate ActionScript file and import them into the Mxml file.
4, CSS
Change the visual style of a component by setting its properties. There are usually four ways to control: by Topic (theme), by definition in a CSS file, by a style block in a mxml file, and by setting in an instance of a component.
5, Graphics resources
Flex contains a variety of graphical resources, such as icons and images.
6, Data
You can associate these components with data in a variety of ways, such as using arrays, collecting objects, data models, and external XML data.
compiling and publishing of Flex applications:
All elements are compiled or connected to the flex application. The flex application is compiled into a SWF file and then run under Flash Player. When a source code is compiled, it is converted into ActionScript classes and merged into a SWF file with graphics and other resources. At run time, the SWF file interacts with the required external libraries, services, and data sources.
Connection Data
Flex applications do not connect directly to a database and can manipulate and manage data using Mxml and ActionScript code. In an application, you can use the Httpservice component to get data from an XML file generated by PHP.
The first step in connecting to a database is to generate the data that will be used in the Flex program. In the application with PHP, use the following steps: 1, create a database (such as MySQL), 2, write a PHP script to connect the MySQL database and production of XML format data;
For XML format data generated by PHP, you can use the Httpservice component to request data acquisition: < mx:application xmlns:mx = "http://www.adobe.com/2006/mxml" layout = " Absolute ">
< Mx:httpservice
id = "Productsrequest"
url = "http://www.somesite.com/products.php"/>
...
The Httpservice component defines a request ID, which provides the URL of the data or the binding between the server and the data.
By binding data to data-driven control, you are able to process Httpservice results (XML data), as follows: < Mx:datagrid x = "Y" = "4" id = "Productgrid" "The width =" A. 00 "
Dataprovider = "{ProductRequest.lastResult.products.items}" >
< Mx:columns >
< Mx:datagridcolumn HeaderText = "name" DataField = "name"/>
< Mx:datagridcolumn HeaderText = "price" DataField = "Price"/>
</mx:columns >
The data structure of </Mx:datagrid > Its XML data source is as follows: < XML >
< Products >
< item >
< name > Mobile Phone </name >
< price > $199 </price >
</Item >
< item >
< name > Car Charger </name >
< price > $34 </price >
</Item >
...
You can also load data in the events of the Flex program component, as follows when the Flex program starts running: < mx:application xmlns:mx = "http://www.adobe.com/2006/mxml" layout = " Absolute "
Creationcomplete = "productsrequest.send ()" >
Flash Player Security issues
Applications running in Flash Player on the client can access a remote data source only if one of the following conditions is true:
1. The SWF file compiled by the application is in the same domain as the remote data source;
2, the use of proxies (proxy), and your SWF file in the same server as the agent;
3, install the Crossdomain.xml (Cross-domain policy) file on the host Web server of the data source.
using layouts, events, and behaviors
The following sample code demonstrates simple layouts, styles, and events. XML version = "1.0" encoding = "Utf-8"?>
<!--MXML Files
All the specifics of the flex application are in the < mx:application > tag Team
All tags in the mxml file have an MX prefix that represents the Flex design namespace-->
< mx:application xmlns:mx = "http://www.adobe.com/2006/mxml" layout = "Absolute" >
<!--< Mx:style Source = "Style.css"/> Applying styles using CSS files-->
<!--use style blocks to apply styles and set the style of textarea (text boxes)-->
< Mx:style >
TextArea ... {
font-size:36px;
Font-weight:bold;
}
</Mx:style >
<!--define action-appropriate functions, ActionScript script-->
< Mx:script >
<! [cdata[
Public function Close (): void ... {
Mypanel.visible=false;
}
]] >
</mx:script >
<!--define special effects-->
< Mx:fade ID = "Myfade"/>
< Mx:panel ID = "Mypanel" layout = "Absolute"