学习Flex:常见的Flex代码

作者:网络 来源:佚名 更新时间:2009-07-20 18:24:56 点击:

1.复制内容到系统剪贴板
system.setclipboard(strcontent);


2.复制一个arraycollection

   //dummy solution( well, it works )
   var bar:arraycollection = new arraycollection();
   for each ( var i:object in ac ){
       bar.additem( i );
   }
   // fantastic ! //
   var bar:listcollectionview = new listcollectionview( listcollectionview( ac ).list );


3.打开一个新浏览器窗口
navigatetourl(new urlrequest('http://ntt.cc'), '_blank');


4.刷新浏览器
navigatetourl(new urlrequest("javascript:location.reload();"),"_self")


5.关闭浏览器
navigatetourl(new urlrequest("javascript:window.close()"),"_self");


6.设置alert 窗口的背景为透明
alert
    {
    modaltransparency:0.0;  
    modaltransparencyblur:0;
    }


7.取随机颜色

lbl.setstyle('color', 0xffffff*math.random());

8.清除子串左侧空格

public function ltrim(s : string):string
    {
      var i : number = 0;
      while(s.charcodeat(i) == 32 || s.charcodeat(i) == 13 || s.charcodeat(i) == 10 || s.charcodeat(i) == 9)
      {
        i++;
      }
      return s.substring(i,s.length);
    }

9.清除字串右侧空格
public function rtrim(s : string):string
    {
      var i : number = s.length - 1;
      while(s.charcodeat(i) == 32 || s.charcodeat(i) == 13 || s.charcodeat(i) == 10 ||s.charcodeat(i) == 9)
      {
        i--;
      }
      return s.substring(0,i+1);
    }

10.清除字串左右的空格
public function trim(s : string):string
    {
      return ltrim(rtrim(s));
    }

11.获取数据类型

getqualifiedclassname(data)

12.生成随机字符串.
private function generatecheckcode():string
   {
       //init
       var ran:number;
       var number:number;
       var code:string;
       var checkcode:string ="";
       //get 4 radom
      for(var i:int=0; i<4; i++)
      {
          ran=math.random();
          number =math.round(ran*10000);            //get result like 0.1234
          if(number % 2 == 0)
            code = string.fromcharcode(48+(number % 10));        //0's ascii code is 48
          else
            code = string.fromcharcode(65+(number % 26)) ;        // a's ascii code is 65
          checkcode += code;
      }
      return checkcode;
}