我的flex笔记(by flash builder4.5)

表格中选取某行数据进行处理
import spark.components.Grid;
import spark.events.GridSelectionEvent;
protected function selectionChangeHandler(event:GridSelectionEvent):void {
const eventGrid:Grid = event.currentTarget.grid;
var currentIndx:int = eventGrid.selectedIndex;
var currentDataItem:Object = eventGrid.selectedItem;
selIndex.text = String(currentIndx);
selLName.text = String(currentDataItem.lastName);
}
---------------------------
click="语句1;语句2" CLICK事件中的语句可以通过分号来分开并行
-----------------------------
数据绑定方式1
<?xml version="1.0"?>
<!-- binding/BasicBinding.mxml -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:TextInput id="myTI" text="Enter text here"/>
<s:Label id="myText" text="{myTI.text}"/>
</s:Application>
----------------------------------------
数据绑定方式2
<?xml version="1.0"?>
<!-- binding/BasicBindingWithAS.mxml -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:TextInput id="myTI"/>
<s:Label id="myText" text="{myTI.text.toUpperCase()}"/>
</s:Application>
--------------------------
数据绑定方式3
<?xml version="1.0"?>
<!-- binding/BasicBindingMXML.mxml -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Binding source="myTI.text" destination="myText.text"/>
<s:TextInput id="myTI"/>
<s:Label id="myText"/>
</s:Application>
---------------------------
数据绑定方式4
<?xml version="1.0"?>
<!-- binding/BasicBindingAS.mxml -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.binding.utils.*;
// Define data binding.
public function initBindingHandler():void {
BindingUtils.bindProperty(myText, "text", myTI, "text");
}
]]>
</fx:Script>
<s:TextInput id="myTI"/>
<s:Label id="myText" preinitialize="initBindingHandler();"/>
</s:Application>
使用外部数据进行绑定
<?xml version="1.0"?>
<!-- binding/FontPropertyBinding.mxml -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
// Define public vars for tracking font size.
[Bindable]
public var maxFontSize:Number = 15;
[Bindable]
public var minFontSize:Number = 5;
]]>
</fx:Script>
<s:Label text="{maxFontSize}"/>
<s:Label text="{minFontSize}"/>
<s:Button click="maxFontSize=20; minFontSize=10;"/>
</s:Application>
-------------------------------------------
显示LIST中的数据和index
<?xml version="1.0" encoding="utf-8"?>
<!-- dpcontrols\sparkdpcontrols\SparkListSelected.mxml -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
height="450">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import spark.events.IndexChangeEvent;
protected function selectionChangedHandler(event:IndexChangeEvent):void
{
var currentIndx:int = event.currentTarget.selectedIndex;
var currentDataItem:Object = event.currentTarget.selectedItem;
selIndex.text = String(currentIndx);
selLName.text = String(currentDataItem.lastName);
}
]]>
</fx:Script>
<s:List id="myList"
labelField="firstName"
change="selectionChangedHandler(event)">
<mx:ArrayCollection>
<fx:Object firstName="Bill" lastName="Smith" companyID="11233"/>
<fx:Object firstName="Dave" lastName="Jones" companyID="13455"/>
<fx:Object firstName="Mary" lastName="Davis" companyID="11543"/>
<fx:Object firstName="Debbie" lastName="Cooper" companyID="14266"/>
</mx:ArrayCollection>
</s:List>
<s:Label text="Selected index:"/>
<s:TextArea id="selIndex" height="50"/>
<s:Label text="Selected Last Name:"/>
<s:TextArea id="selLName" height="50"/>
</s:Application>
---------------------------------------------
<?xml version='1.0' encoding='UTF-8'?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import mx.effects.DefaultListEffect;
import mx.collections.ArrayCollection;
[Bindable]
private var myDP:ArrayCollection= new ArrayCollection(
['A','B','C','D','E','F','G','H']);
private function deleteItem():void {
// As each item is removed, the index of the other items changes.
// So first get the items to delete, then determine their indices
// as you remove them.
var toRemove:Array = [];
for (var i:int = 0; i < list0.selectedItems.length; i++)
toRemove.push(list0.selectedItems);
for (i = 0; i < toRemove.length; i++)
myDP.removeItemAt(myDP.getItemIndex(toRemove));
}
private var zcount:int = 0;
private function addItem():void {
// Always add the new item after the third item,
// or after the last item if the length is less than 3.
myDP.addItemAt("Z"+zcount++,Math.min(3,myDP.length));
}
]]>
</fx:Script>
<!-- Define an instance of the DefaultListEffect effect,
and set its fadeOutDuration and color properties. -->
<fx:Declarations>
<mx:DefaultListEffect id="myDLE"
fadeOutDuration="1000"
color="0x0000ff"/>
</fx:Declarations>
<s:Panel title="Halo DefaultListEffect Example" width="75%" height="75%" >
<s:VGroup left="20" right="20" top="20" bottom="20">
<mx:List id="list0"
width="150"
dataProvider="{myDP}"
variableRowHeight="true"
fontSize="18"
allowMultipleSelection="true"
itemsChangeEffect="{myDLE}"/>
<s:Button
label="Delete item"
click="deleteItem();"/>
<s:Button
label="Add item"
click="addItem();"/>
</s:VGroup>
</s:Panel>
</s:Application>
Tags: 

延伸阅读

最新评论

发表评论