Flex 中 12 个简单但是很有用的函数

   No matter what kind language using programmer will always accumulate many useful and daily using function with rich in development experience day by day. And then the accumulation become to a library at last. Of course it’s include the flex programmers. Following is some very basic, very simple functions which I’ve collected. How about you? If have any proudly and recommendable functions? Then, don’t only stock in your head, leave your comments. Let’s share.

No.1 Copy content to clipboard: 



System.setClipboard(strContent);



No.2 Clone an 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 );

No.3 Open URL: 



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



No.4 Page reload: 



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



No.5 Close browse: 



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



No.6 Set the background alpha to transparent on Alert window: 



Alert  

{  

modalTransparency:0.0;   

modalTransparencyBlur:0; 

}



No.7 Set random color: 



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



No.8 Trim left of white space 



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

}



No.9 Trim right of white space 



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

}



No.10 Trim left and right of white space 



public function Trim(s : String):String  

{  

  return LTrim(RTrim(s)); 

}



No.11 get data type: 



getQualifiedClassName(data)

No.12 Generate check digits 



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; 

}
转自:http://blog.chinahr.com/blog/srivatsa/post/89728
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值