Flex3.权威指南.第二讲-笔记
时间:2010-08-18 来源:myuser
1.<mx:Image source="@Embed('assets/dairy_milk.jpg')" scaleContent="true"
mouseOver="this.currentState='expanded'"
mouseOut="this.currentState=''"/>
@Embed 资源文件直接包含到swf中去。
2.视图状态中,添加一些元素。
<mx:State name="cartView">
<mx:SetProperty target="{products}" name="width" value="0"/>
<mx:SetProperty target="{products}" name="height" value="0"/>
<mx:SetProperty target="{cartBox}" name="width" value="100%"/>
<mx:AddChild relativeTo="{cartBox}" position="lastChild">
<mx:DataGrid id="dgCart" width="100%">
<mx:columns>
<mx:DataGridColumn headerText="Column 1" dataField="col1"/>
<mx:DataGridColumn headerText="Column 2" dataField="col2"/>
<mx:DataGridColumn headerText="Column 3" dataField="col3"/>
</mx:columns>
</mx:DataGrid>
</mx:AddChild>
<mx:AddChild relativeTo="{cartBox}" position="lastChild">
<mx:LinkButton label="Continue Shopping" click="this.currentState=''"/>
</mx:AddChild>
<mx:RemoveChild target="{linkbutton1}"/>
</mx:State>
3.数据结构
<mx:Model id="groceryInventory">
<groceries>
<catName>Dairy</catName>
<prodName>Milk</prodName>
<imageName>assets/dairy_milk.jpg</imageName>
<cost>1.20</cost>
<listPrice>1.99</listPrice>
<isOrganic>true</isOrganic>
<isLowFat>true</isLowFat>
<description>Direct from California where cows are happiest!</description>
</groceries>
</mx:Model>
绑定数据
<mx:Text text="{groceryInventory.description}" width="50%"/>
如果数据结构改变,界面上相应的绑定数据也会改变。
4. as3
<mx:Script>
<![CDATA[
import flash.net.FileReference;
public function fileBrowse():void{
var myFileRef:FileReferenceList = new FileReferenceList();
myFileRef.browse();
}
]]>
</mx:Script>
5. <mx:Form>
6. 使用外部数据结构
<mx:Model id="groceryInventory" source="assets/inventory.xml"/>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="prodHandler(groceryInventory)">
creationComplete程序里的所有空间加载好后,执行这里的方法。
private function prodHandler(theItems:Object):void
{
theProduct = Product.buildProduct(theItems);
trace(theProduct);
}
7. 要使用trance() 需要安装flash player debug版本。
8. actionscript class
mxml中的控件使用这些类,import.
<mx:Script>
<![CDATA[
import valueObjects.Product;
import valueObjects.ShoppingCartItem;
import valueObjects.ShoppingCart;
[Bindable]
public var cart:ShoppingCart = new ShoppingCart();
9. static