1、让程序等待一段时间
private function eqReportTypeFilter(type:String):void {
var t:Timer = new Timer(500, 1);
t.addEventListener(TimerEvent.TIMER, handler);
t.start();
}
private function handler(event:TimerEvent):void {
eqReportTypeFilter1('reporting');
}
2、计算运行时间
var startTime:Number;
var endTime:Number;
startTime = (new Date()).time;
//........
endTime = (new Date()).time;
3、Flex Cairngorm.as 单实例写法
4、Flex DTO 定义
package com.citi.gpf.ah.core.dto.group
{
import mx.collections.ArrayCollection;
[Bindable]
[RemoteClass(alias="com.citi.gpf.ah.core.dto.group.GrpDto")]
public class GrpDto
{
public var pfGrpId:Number;
public var pfRootId:Number;
...
}
}
5、Flex Object 奇怪的用法
public function init():void {
var student:Object = new Object();
student.name = "David";
student.age = 20;
student.type = "master";
for (var prop:String in student) {
trace(prop+":"+student[prop]);
}
trace("#########");
for each (var value: * in student) {
trace(value);
}
}
6. combobox
<mx:ComboBox id="myComboBox" width="171" x="10" y="10">
<mx:dataProvider>
<mx:Array>
<mx:String>ComboBox1</mx:String>
<mx:String>ComboBox2</mx:String>
<mx:String>ComboBox3</mx:String>
</mx:Array>
</mx:dataProvider>
</mx:ComboBox>
< mx:ComboBox id = " comboBox " dropdownStyleName = " myCustomDropdownStyleName " > < mx:dataProvider > < mx:Array > < mx:Object label = " One " /> < mx:Object label = " Two " /> < mx:Object label = " Three " /> < mx:Object label = " Four " /> < mx:Object label = " Five " /> < mx:Object label = " Six " /> < mx:Object label = " Seven " /> </ mx:Array > </ mx:dataProvider > </ mx:ComboBox >
array的定义
private var pairs:Array = ["AUDUSD","EURJPY","EURUSD","GBPJPY","GBPUSD","NZDUSD","USDCAD","USDCHF","USDJPY"];
7. 常量的定义
public class ActionType
{
public static const ACT_NORMAL:int = 0;
public static const ACT_SAVEUPD:int = 1;
public static const ACT_DEL:int = 2;
}
8、httpservice用法
private function init():void {
var t:Timer = new Timer(15000, 0);
t.addEventListener(TimerEvent.TIMER, httpConnection);
t.start();
}
private function httpConnection(event:TimerEvent):void {
loader.url = "http://www.dailyfx.com.hk/informer/fxcm_pricedde_sc.php ";
var params:Object = {};
params['temp'] = 1;
loader.send(params);
}
<mx:HTTPService id="loader" resultFormat="text" method="GET"
result="resultParse(event)" showBusyCursor="true"/>
9、ArrayCollection 排序
private function sortBySystemName(ac:ArrayCollection):void {
if (ac != null && ac.length>0) {
var sort:Sort=new Sort();
sort.fields=[new SortField('systemName'), new SortField('pairName')];
ac.sort=sort;
ac.refresh();
ac.sort=null;
}
}
10. 一种绑定的写法
<mx:Label text="Performance Amount : {Models.fxModel.criteriaedPerformances.length}"/>
11. 随机数的例子
基本的Random函数如下
Math.random();
可以产生出0-1之间的任意小数,例如0.0105901374530933 或
0.872525005541986,有几个其他的函数可以用来改变产生的数字,从而可以更好的在你的影片中使用:
Math.round();
Math.ceil();
Math.floor();
这几个函数都是用来取得整数的,Math.round(); 是采用四舍五入方式取得最接近的整数。Math.ceil(); 是向上取得一个最接近的整数,Math.floor();
和Math.ceil(); 相反,Math.floor(); 向下 取得一个最接近的整数
结合这些函数,你就可以这样写:
Math.round(Math.random());
这个表达式可以生成一个0.0和1.0之间的一个数,然后四舍五入取得一个整数。这样所生成的数字就是0或1。这个表达式可以用在各有50%的可能的情况下,例如抛硬币,或者true/false指令。
*10 是将你所生成的小数乘以10,然后四舍五入取得一个整数:
Math.round(Math.random()*10);
要创建一个1到10之间的随机数,可以这样写:
Math.ceil(Math.random()*10);
应为是Math.ceil向上取值,所以不会产生0。要创建一个5到20的随机数可以这样写
Math.round(Math.random()*15)+5;
也就是说,如果要创建一个从x到y的随机数,就可以这样写
Math.round(Math.random()*(y-x))+x;
11.定义 array & arrayCollection
[Bindable]
public var DECKER:Array = [
{date:"11-Aug-05",close:44},
{date:"12-Aug-05",close:46.1}
];
[Bindable]
private var expensesAC:ArrayCollection = new ArrayCollection( [
{ Month: "Jan", Profit: -200, Expenses: 1500, Amount: 500 },
{ Month: "Feb", Profit: 1000, Expenses: 200, Amount: 600 },
{ Month: "Mar", Profit: 1500, Expenses: -500, Amount: 300 } ]);