Flex 3 learning Summary

Source: Internet
Author: User
Flex 3 learning Summary

-------------------- Repeater ---------------

<Mx: RepeaterId = "foodrepeater"
Width = "100%" Height = "100%"
Dataprovider= "{Prodbycategory}">
<V: grocerydetail id = "Prod"
Width = "80%"
Groceryitem ="{Foodrepeater. currentitem}"/>
</MX: repeater>

------------------ XML search method ------------

Private function prodbycategoryhandler (Event: resultevent): void {
Rawdata = event. result as XML;

For each(VARC: XMLIn event.Result .. category){
VaR category: Category = new category (INT (C. @ catid), string (C. @ catname ));
Acats. Push (category );//The object category is pushed into the array.
Categorizedproducts [C. @ catid] = new array ();
For each(VARP: XMLInC. Product){
VaR prod: Product = new product (number (P. @ catid ),
String (P. @ prodname ),
Number (P. @ unitid ),
Number (P. @ cost ),
Number (P. @ listprice ),
String (P. @ description ),
Boolean (P. @ isorganic = "yes "),
Boolean (P. @ islowfat = "yes "),
String (P. @ imagename ));
Categorizedproducts [C. @ catid]. Push (prod );
}
}
If (this. parentdocument.Categorizedproductdataloaded! = NULL ){
This. parentdocument.Categorizedproductdataloaded(Acats );
}
}

------------------------ Model ----------------------

Model requires a root node, such as product

<Mx: Model id = "prodmodel">
<Product>
<Catid >{ int (catid. selecteditem. catid)} </catid>
<Prodname> {prodname. Text} </prodname>
<Unitid> {unitid. selecteditem. unitid} </unitid>
<Cost> {number (cost. Text)} </cost>
<Listprice >{number (listprice. Text)} </listprice>
<Description> {description. Text} </description>
<Isorganic >{isorganic. Selected} </isorganic>
<Islowfat> {islowfat. Selected} </islowfat>
<Imagename> {imagename. Text} </imagename>
</Product>
</MX: Model>

----------------------- Pop-up of custom components ----------------

Private var win:Confirmscreen; // Window component class

Private function doprodadd (): void {
VaR prod: Product = product. buildproduct (prodmodel );
Showpopup(Prod, "product" + prodmodel. prodname + "added ");
}

Private function showpopup (prod: product, Title: string): void {
Win =Confirmscreen (popupmanager. createpopup (this, confirmscreen, true ));
Win. Prod = prod;//// Transfer Parameters
Win. Title = title;
}

----------------------- Close of custom components --------------

<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: titlewindow xmlns: MX = "http://www.adobe.com/2006/mxml"
Layout = "vertical"
Close = "popupmanager. removepopup (this )"
Showclosebutton = "true">

<Mx: SCRIPT>
<! [CDATA [
Import MX. Managers. popupmanager;

----------------------- Use of the cursor --------------------

Import MX. Collections. iviewcursor;
Private VaRCursor: iviewcursor;
Cursor = arraycollection.Createcursor ();
VaR found: Boolean = cursor.Findfirst(Classobject );
VaR SCI: shoppingcartitem =Cursor. CurrentAs shoppingcartitem;
Cursor.Remove (); and The findany () and findlast () Methods

------------------------ Sort arraycollection by sort ----------------

VaR prodsort: Sort = new sort ();
VaR sortfield: sortfield = new sortfield ("product ");////////// Sortfield has three optional parameters: Case sensitivity (default), ascending/descending order (default descending order ), number order or alphabetic order (default alphabetic order)
Prodsort. Fields = new array (sortfield );//// You can also combine these two sentences: var sortfield1: sortfield = new sortfield ("product ");
Myarraycollection. Sort = prodsort;
Myarraycollection. Refresh ();

------------------------ Conversion Type ---------------------

Addtocart (groceryinventory. getitemat (0) as product) converts groceryinventory. getitemat (0) to the product class

------------------------- Settings of selectindex -----------

When selectindex =-1, the control does not select any project.

------------------------- Attribute conversion -------------------------

Number (P. @ catid), string (P. @ prodname), Boolean (P. @ isorganic = "yes ")

-------------------------- Define arraycollection ---------------

AC = new arraycollection (
[
{"Firstname": "Christopher", "lastname": "lapber "},
{"Firstname": "Dean", "lastname": "hownson "},
]
);

--------------------------- Application initial execution function ----------

Initialize = "Init ()"

======================== E4X ==============================

E4X expression:
1. Using E4X, you do not need to include the root node in the statement
2,. Show all nodes
<Catalog>
<Category name = "Vegetables">
<Product name = "lettuce" cost = "1.95">
<Unit> bag </unit>
<DESC> cleaned and bagged </DESC>
</Product>
<Product name = "Carrots" cost = "2.95">
<Unit> pound </unit>
<DESC> baby carrots, cleaned and peeled </DESC>
</Product>
</Category>
<Category name = "Fruit">
<Product name = "Apples" cost = "1.95">
<Unit> Each </unit>
<DESC> sweet Fuji </DESC>
</Product>
<Berries>
<Product name = "raspberries" cost = "3.95">
<Unit> pint </unit>
<DESC> firm and fresh </DESC>
</Product>
<Product name = "Strawberries" cost = "2.95">
<Unit> pint </unit>
<DESC> deep red and juicy </DESC>
</Product>
</Berries>
</Category>
</CATALOG>
3,Category. Product: displays all nodes of the product tag.
<Product name = "lettuce" cost = "1.95">
<Unit> bag </unit>
<DESC> cleaned and bagged </DESC>
</Product>
<Product name = "Carrots" cost = "2.95">
<Unit> pound </unit>
<DESC> baby carrots, cleaned and peeled </DESC>
</Product>
<Product name = "Apples" cost = "1.95">
<Unit> Each </unit>
<DESC> sweet Fuji </DESC>
</Product>
4,Category. Product. Unit: display unit tag subnodes
<Unit> bag </unit>
<Unit> pound </unit>
<Unit> Each </unit>
5,Category. Product [0]: 0th tags
<Product name = "lettuce" cost = "1.95">
<Unit> bag </unit>
<DESC> cleaned and bagged </DESC>
</Product>
6,Category. Product. (unit = "each") Search node values
<Product name = "Apples" cost = "1.95">
<Unit> Each </unit>
<DESC> sweet Fuji </DESC>
</Product>
7,Category. Product. (@ name = "Carrots") Search for values in attributes
<Product name = "Carrots" cost = "2.95">
<Unit> pound </unit>
<DESC> baby carrots, cleaned and peeled </DESC>
</Product>
8,Category. Product. (@ name = "Carrots"). (unit = "pound") Multi-condition search
Or category. Product. (unit = "pound"). (@ name = "Carrots ")
<Product name = "Carrots" cost = "2.95">
<Unit> pound </unit>
<DESC> baby carrots, cleaned and peeled </DESC>
</Product>
9,CATEGORY .. product explore all product tags
<Product name = "lettuce" cost = "1.95">
<Unit> bag </unit>
<DESC> cleaned and bagged </DESC>
</Product>
<Product name = "Carrots" cost = "2.95">
<Unit> pound </unit>
<DESC> baby carrots, cleaned and peeled </DESC>
</Product>
<Product name = "Apples" cost = "1.95">
<Unit> Each </unit>
<DESC> sweet Fuji </DESC>
</Product>
<Product name = "raspberries" cost = "3.95">
<Unit> pint </unit>
<DESC> firm and fresh </DESC>
</Product>
<Product name = "Strawberries" cost = "2.95">
<Unit> pint </unit>
<DESC> deep red and juicy </DESC>
</Product>
10,CATEGORY .. product. (@ cost> 2)
<Product name = "Carrots" cost = "2.95">
<Unit> pound </unit>
<DESC> baby carrots, cleaned and peeled </DESC>
</Product>
<Product name = "raspberries" cost = "3.95">
<Unit> pint </unit>
<DESC> firm and fresh </DESC>
</Product>
<Product name = "Strawberries" cost = "2.95">
<Unit> pint </unit>
<DESC> deep red and juicy </DESC>
</Product>

--------------------- ComboBox binds data and adds "select "-------------

Import MX. Collections. arraycollection;
Import MX. rpc. Events. resultevent;

[Bindable]
Private var categories: arraycollection = new arraycollection ();

Private function cathandler (Event: resultevent): void {
Categories = event. Result. Catalog. category;
VaR catobj: Object = new object ();
Catobj. Name = "select ";
Catobj. categoryid = 0;
Categories. additemat (catobj, 0 );

Catcombo. selectedindex = 0;
}

<Mx: ComboBox id = "catcombo"
Dataprovider= "{Categories}"
Labelfield= "Name"/>

---------------- Use of dataprovider and arraycollection -----------

<Mx: ComboBoxLabelfield= "Type">
<Mx: dataprovider>
<Mx: arraycollection>
<Mx: object type = "Fruit" value = "zero"/>
<Mx: object type = "fruit1" value = "zero1"/>
</MX: arraycollection>
</MX: dataprovider>
</MX: ComboBox>

----------------- Cross-origin policy file -----------------

Flex complies with the Security Sandbox restrictions of Flash Player.

Crossdomain. XML, located in the root directory of the Web server called by the SWF file, specifies which domains can access resources through Flash Player. The following code allows any SWF to access available resources on the server where the cross-origin policy file is located.

<Cross-domain-Policy>
<Allow-access-from domain = "*"/>
</Cross-Domain-Policy>

Http://www.cnn.com/crossdomain.xml

First, confirm that you have understood all the consequences and then use them.

----------------- Httpservice obtains data --------

1. Use the lastresult: httpserviceid. lastresult. xml Node

----------------- Create an httpservice object -------

Steps:
1. Create an httpservice object.
2. Call the send () method in the object.
3. Use the returned data.

----------------- Use trace ----------- in the class -----------

Import flash. utils .*

Trace ("");

------------------ Point -----------------

This. Object object refers to the variables in this class, which can distinguish between local variables.

------------------- How to view the created ActionScript --------------

When a flex project is created, a class is generated from the application class.
If you want to see the created ActionScript, you can add a parameter in flex builder.
Project-> properties-> flex complier-> additional complier arguments
Add existing parameters-Keep-generated-ActionScript

In your project, a folder named generated is automatically created, which contains many ActionScript files and the name of the actual application file is named in the form of a Name-generated.as.After checking, do not forget to delete this compiler parameter.

------------------ Breakpoint debugger description --------------------

In the name column, the "L" icon indicates that it is a local variable.

------------------ Use data from the event object ----------------

Type: the type in the event is a string that contains the name of the event to be processed, such as click or creationcomplete.

Target: indicates the component that distributes the event. For example, when you click the event generated by the button, target indicates the button event.

---------------------- Model -----------------------

You can place an <mx: Model> tag in a flex application file, or in an mxml component file. the tag must have an id value. it cannot be the root tag of an mxml component. the <mx: Model> tag has the following syntax:

<Mx: Model id = "modelid">
Model declaration put XML data here
</MX: Model>

 

 

Or:

<mx:Model id="modelID" source="fileName" />

------------------ Creationcomplete event --------------

Each child element has a creationcomplete. The execution sequence is: first child element, then Application

Therefore, executing the creationcomplete event in the application is the proper time to request and use data from external resources.

If you are responding to multiple events, you can add ";", for example, creationcomplete = "fun1 (); fun2 ()"

--------------------- Bind ------------------

{} Is used to bind the property value.

--------------------- Form -------------

<Mx: Form>
<Mx:Formheading Label= "{Prodmodel. catname}"/>Title
<Mx:Formitem Label= "Product Name">
<Mx: textinput id = "product" text = "{prodmodel. prodname}"/>Content name (controls can be placed in it)
</MX: formitem>
</MX: Form>

-------------------- Checkbox -----------------

<Mx: checkbox id = "islowfat"Selected= "{Prodmodel. islowfat}"/>

------------------ Image control -------------------

<Mx: Image Source = "@Embed('Assets/dairy_milk.jpg ') "scalecontent =" true"
Mouseover = "This. currentstate = 'expanded '"
Mouseout = "This. currentstate ='' "/>

@ Embed the image into SWF. When the SWF is loaded, the image has been loaded without waiting. The disadvantage is that the SWF file will become very large.

//// // View status //////////////

How to switch the view status:

<Mx: linkbutton label = "Base Status"
Click = "this.Currentstate=''"/> Indicates that the status is no longer displayed.
<Mx: linkbutton label = "sub-state"
Click = "this.Currentstate='Childstate'"/>

///////////// Container knowledge //////////////////////

Role: controls can be managed by group.
Canvas: controls are located at 0 to 0 by default.
Tile:
Panel: With titles, and statuses

///////////// Enter How to Write //////////////////

Assign label. Text = "dfasdfsf/R/n zxcsdfasd" to the"
Assign text = "dfasdfas & #13; dfasdfa" to mxml"

--------------

Differences between label and text

The items in the label cannot be copied, but those in the text can.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.