--------------------Repeater---------------
<mx:Repeater id="foodRepeater" width="100%" height="100%" dataProvider="{prodByCategory}"> <v:GroceryDetail id="prod" width="80%" groceryItem="{foodRepeater.currentItem}"/></mx:Repeater>
--------------------XML搜索方法------------
private function prodByCategoryHandler(event:ResultEvent):void{ rawData=event.result as XML;
for each(var c:XML in event.result..category){ var category:Category = new Category(int(c.@catID),String(c.@catName)); aCats.push(category);//对象category压入数组 categorizedProducts[c.@catID] = new Array(); for each (var p:XML in c..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需要有一个根节点,如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>
-----------------------自定义组件的弹出----------------
private var win:ConfirmScreen;//窗口组件类
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;传递参数 win.title = title; }
-----------------------自定义组件的关闭--------------
<?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;
-----------------------光标的使用--------------------
import mx.collections.IViewCursor;private var cursor:IViewCursor;cursor = ArrayCollection.createCursor();var found:Boolean = cursor.findFirst(classObject);var sci:ShoppingCartItem = cursor.current as ShoppingCartItem;cursor.remove();还有findAny(),findLast() 方法
------------------------对ArrayCollection进行Sort排序----------------
var prodSort:Sort=new Sort(); var sortField:SortField=new SortField("product");SortField有三个参数可选,是否区分大小写(默认区分),升降序(默认降序),数字顺序还是字母顺序(默认字母顺序) prodSort.fields=new Array(sortField);/还可以把这二句合成:var sortField1:SortField=new SortField("product"); myArrayCollection.sort=prodSort; myArrayCollection.refresh();
------------------------转换类型---------------------
addToCart(groceryInventory.getItemAt(0) as Product) 把groceryInventory.getItemAt(0) 转为Product类
-------------------------selectIndex的设置-----------
当selectIndex=-1表示该控件没有选中任何项目
-------------------------属性的转换-------------------------
Number(p.@catID),String(p.@prodName),Boolean(p.@isOrganic=="Yes")
--------------------------定义ArrayCollection---------------
ac=new ArrayCollection([{"firstname": "Christopher", "lastName": "Lapber"},{"firstname": "Dean", "lastName": "Hownson"},]);
---------------------------Application初始执行函数----------
initialize="init()"
=================E4X================
E4X Expression:1、使用e4x,不需要在语句中包含根节点2、. 显示所有节点<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 显示product标签所有节点<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 显示unit标签子节点<unit>bag</unit><unit>pound</unit><unit>each</unit>5、category.product[0] 指定第0个标签<product name="lettuce" cost="1.95"><unit>bag</unit><desc>Cleaned and bagged</desc></product>6、category.product.(unit=="each") 搜索节点的值<product name="apples" cost="1.95"><unit>each</unit><desc>Sweet Fuji</desc></product>7、category.product.(@name=="carrots") 搜索属性里的值<product name="carrots" cost="2.95"><unit>pound</unit><desc>Baby carrots, cleaned and peeled</desc></product>8、category.product.(@name=="carrots").(unit=="pound") 多条件搜索或者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 探索所有product标签<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绑定数据并添加“请选择”-------------
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 = "请选择"; catObj.categoryID = 0; categories.addItemAt(catObj, 0); catCombo.selectedIndex = 0; }
<mx:ComboBox id="catCombo" dataProvider = "{categories}" labelField = "name"/>
------------------dataProvider、ArrayCollection的使用-----------
<mx:ComboBox labelField="type" ><mx:dataProvider> <mx:ArrayCollection> <mx:Object type="Fruit" value="zero"/> <mx:Object type="Fruit1" value="zero1"/> </mx:ArrayCollection></mx:dataProvider></mx:ComboBox>
-----------------跨域策略文件-----------------
Flex 遵守Flash Player的安全沙箱限制。
crossdomain.xml,位于SWF文件调用的Web服务器的根目录下,指定哪些域可以通过Flash Player访问其中的资源。下面的代码可以允许任何SWF访问跨域策略文件所在服务器上的可用资源。
<cross-domain-policy><allow-access-from domain="*" /> </cross-domain-policy>
http://www.cnn.com/crossdomain.xml
请先确定已经了解了其将承担的所有后果后使用。
-----------------HTTPService获取数据--------
1、使用lastResult: HTTPServiceID.lastResult.XML节点
-----------------创建HTTPService对象-------
步骤:1、创建一个HTTPService对象。2、调用对象中的send()方法。3、使用返回的数据。
-----------------在类中使用trace-----------
import flash.utils.*
trace(" ");
------------------this的指向-----------------
this.object object是指的是这个类中的变量,可以区分局部变量
-------------------如何看创建的ActionScript--------------
在创建时Flex Project时,就会从Application类中派生出一个类。如果想看创建的ActionScript,可以在Flex Builder中添加一个参数。Project->Properties->Flex Complier->Additional complier arguments在现有的参数后面添加 -keep-generated-actionscript
在你的项目里将会自动创建一个名叫generated的文件夹,里面有许多ActionScript文件,实际应用程序文件命名会以Name-generated.as的方式命名。当查看完毕,别忘记删除这个编译器参数。
--------------------断点调试器的说明--------------------
Name列中,"L"图标表明它是一个局部变量。
--------------------使用来自事件对象的数据----------------
type:事件中的type是一个字符串,包含了需处理的事件的名称,比如:click或creationComplete
target:代表哪个组件分发了这个事件,比如,单击按钮产生的事件时,target就代表了这个Button事件。
----------------------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 这里面放进XML数据 </mx:Model>
or:
<mx:Model id="modelID" source="fileName" />--------------------creationComplete事件--------------
每一个子元素都会有一个creationComplete,执行顺序为:先子元素,后Application
所以在获取数据的时候,在Application中执行creationComplete事件才是向外部资源请求并使用数据的适当时机。
如果响应多个事件,可以加“;”,比如:creationComplete="fun1();fun2()"
---------------------绑定------------------
给属性值使用 {} 就是绑定
---------------------Form-------------
<mx:Form><mx:FormHeading label="{prodModel.catName}"/>标题<mx:FormItem label="Product Name"> <mx:TextInput id="product" text="{prodModel.prodName}"/>内容名称(可以在里面放控件)</mx:FormItem></mx:Form>
--------------------CheckBox -----------------
<mx:CheckBox id="isLowFat" selected="{prodModel.isLowFat}"/>
------------------Image控件-------------------
<mx:Image source="@Embed('assets/dairy_milk.jpg')" scaleContent="true" mouseOver="this.currentState='expanded'" mouseOut="this.currentState=''"/>
@Embed把图片嵌入到SWF中,加载SWF时,已经加载图片,不需要用户等待;缺点是SWF文件会变很大
视图状态//
如何切换视图状态:
<mx:LinkButton label="基状态" click="this.currentState=''"/>表示其状态不再显示 <mx:LinkButton label="子状态" click="this.currentState='ChildState'"/>
容器的知识//
作用:可以分组来管理控件Canvas:默认是把控件位于0,0位置Tile:Panel:有标题、和状态
回车如何写//
在as中赋值 label.text="dfasdfsf /r/n zxcsdfasd"在mxml中赋值 text="dfasdfas dfasdfa"
--------------
Label 与 Text 的区别
Label里的东西不可以复制,Text里的可以。