Flex Programming Tricks 1

news/2024/5/19 17:00:15 标签: Flex, Flash, PHP, Adobe, performance

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 单实例写法  

  1. package  com.citi.gpf.ah.core.model   
  2. {   
  3.      import  com.adobe.cairngorm.model.ModelLocator;   
  4.            
  5.      import  flash.events.EventDispatcher;   
  6.        
  7.      import  mx.collections.ArrayCollection;   
  8.   
  9.        
  10.     [Bindable]   
  11.      public   class  GroupModelLocator  extends  EventDispatcher  implements  ModelLocator   
  12.     {   
  13.          private   static  var model:GroupModelLocator;   
  14.            
  15.          public   static  function getInstance() : GroupModelLocator {   
  16.              if  ( model ==  null  ) {   
  17.                 model =  new  GroupModelLocator();   
  18.             }                  
  19.              return  model;   
  20.         }   
  21.            
  22.          //public var pfClientList:ArrayCollection=new ArrayCollection();   
  23. }  

 

 

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 } ]);


http://www.niftyadmin.cn/n/1313652.html

相关文章

Tomcat 运行 idea 编译好的 .class JavaWeb 项目

对于新手来说,对于项目部署,有时候就是以为拷贝在idea控制台里面跑的项目放到tomcat里面的webapps里面跑就可以了,这仅仅限于静态项目..... 他不像PHP , 修改源码直接可以跑, 而Java不一样,PHP是最好的语言是有依据的~~~ 而后缀是.java 的,而idea控制台里面跑的是编译后的.clas…

JMX一步步来

http://damies.iteye.com/blog/51788

学习笔记之maven2学习总结(2,进阶setting.xml与pom.xml)

学习笔记之maven2学习总结&#xff08;2&#xff0c;进阶setting.xml与pom.xml&#xff09; 转载自http://rdc.taobao.com/blog/qa/?p560guangyuan 于 2009-2-21,09:59 这篇文章主要是关于maven2的两个配核心置文件的理解&#xff1a;pom.xml和setting.xml。 pom.xml位于创建的…

Java I/O---获取文件目录并写入到文本

首先获取指定目录下的所有文件目录&#xff0c;存入List集合中&#xff0c;然后创建文本文件将List遍历写入文本中保存。 1.主程序类 1 public class Test {2 3 /**4 * param args5 */6 public static void main(String[] args) {7 // TODO Auto-generated method stub…

jconsole+tomcat配置说明

最近需要参与一些java程序debug和性能调整方面的工作&#xff0c;jconsole是jdk自带的工具&#xff0c;比较好用&#xff0c;以下文章前面大部分翻译自&#xff1a;http://java.sun.com/j2se/1.5.0/docs/guide/management/jconsole.html &#xff0c;后面关于用户名/密码和使用…

Cassandra代替Redis?

最近用Cassandra的又逐渐多了&#xff0c;除了之前的360案例&#xff0c;在月初的QCon Shanghai 2013 篱笆网也介绍了其使用案例。而这篇百万用户时尚分享网站feed系统扩展实践文章则提到了Fashiolista和Instagram从Redis迁移到Cassandra的案例。考虑到到目前仍然有不少网友在讨…

JavaScript中的时间操作

Js获取当前日期时间及其它操作 var myDate new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); //获取完整的年份(4位,1970-????) myDate.getMonth(); //获取当前月份(0-11,0代表1月) myDate.getDate(); //获取当前日(1-31…

bzoj千题计划177:bzoj1858: [Scoi2010]序列操作

http://www.lydsy.com/JudgeOnline/problem.php?id1858 2018 自己写的第1题&#xff0c;一遍过 ^_^ 元旦快乐 #include<cstdio> #include<iostream> #include<algorithm>using namespace std;#define N 100001struct node {int siz;int L[2],R[2],con[2];in…