FLEX 12个基础 很有用的方法

No.1 复制到系统剪贴板上的文本:
  1. System.setClipboard(strContent);

No.2 克隆一个ArrayCollection:

  1. //dummy solution( well, it works )
  2. var bar:ArrayCollection = new ArrayCollection();
  3. for each ( var i:Object in ac ){ 
  4. bar.addItem( i );
  5. } 
  6. // fantastic ! //
  7. var bar:ListCollectionView = new ListCollectionView( ListCollectionView( ac ).list );

No.3  打开URL链接:

  1. navigateToURL(new URLRequest('http://ntt.cc'), '_blank'

No.4  重新加载页面:

  1. navigateToURL(new URLRequest("javascript:location.reload();"),"_self")

No.5 关闭浏览器:

  1. navigateToURL(new URLRequest("javascript:window.close()"),"_self");

No.6 设置Alert 背景颜色:

  1. Alert 
  2. { 
  3. modalTransparency:0.0;  
  4. modalTransparencyBlur:0;
  5. }

No.7  设置一个随机颜色:

  1. lbl.setStyle('color', 0xffffff*Math.random());

No.8  剔除左边空格

  1. public function LTrim(s : String):String 
  2. { 
  3.   var i : Number = 0;
  4.   while(s.charCodeAt(i) == 32 || s.charCodeAt(i) == 13 || s.charCodeAt(i) == 10 || s.charCodeAt(i) == 9) 
  5.   { 
  6.     i++;
  7.   } 
  8.   return s.substring(i,s.length);
  9. }

No.9  剔除右边空格

  1. public function RTrim(s : String):String 
  2. { 
  3.   var i : Number = s.length - 1;
  4.   while(s.charCodeAt(i) == 32 || s.charCodeAt(i) == 13 || s.charCodeAt(i) == 10 ||s.charCodeAt(i) == 9) 
  5.   { 
  6.     i--;
  7.   } 
  8.   return s.substring(0,i+1);
  9. }

No.10  剔除2侧空格

  1. public function Trim(s : String):String 
  2. { 
  3.   return LTrim(RTrim(s));
  4. }

No.11 获得数据类型:

  1. getQualifiedClassName(data)

No.12 生成一个验证随机码

  1. private function GenerateCheckCode():String 
  2. { 
  3.     //init
  4.     var ran:Number;
  5.     var number:Number;
  6.     var  code:String;
  7.     var checkCode:String ="";
  8.     //get 4 radom
  9.    for(var i:int=0; i<4; i++) 
  10.    { 
  11.        ran=Math.random();
  12.        number =Math.round(ran*10000);            //get result like 0.1234
  13.        if(number % 2 == 0) 
  14.          code = String.fromCharCode(48+(number % 10));        //0's ASCII code is 48
  15.        else 
  16.          code = String.fromCharCode(65+(number % 26)) ;        // A's ASCII code is 65
  17.        checkCode += code;
  18.    } 
  19.    return checkCode;
  20. }
posted on 2008-04-23 15:29  噢耶游戏  阅读(731)  评论(0编辑  收藏  举报