Flex中12个最基本、最简单但却最有用的函数
No.1 复制内容到剪贴板
- System.setClipboard(strContent);
No.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 );
No.3 打开指定URL的页面(页面导向功能):
- navigateToURL(new URLRequest('http://ntt.cc'), '_blank'
No.4 页面重载:
- navigateToURL(new URLRequest("javascript:location.reload();"),"_self")
No.5 关闭页面:
- navigateToURL(new URLRequest("javascript:window.close()"),"_self");
No.6 设置Alert弹出窗口的背景色为透明:
- Alert
- {
- modalTransparency:0.0;
- modalTransparencyBlur:0;
- }
No.7 设置随机颜色:
- lbl.setStyle('color', 0xffffff*Math.random());
No.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);
- }
No.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);
- }
No.10 去掉字符创两边的空格
- public function Trim(s : String):String
- {
- return LTrim(RTrim(s));
- }
No.11 取得数据类型:
- getQualifiedClassName(data)
No.12 生成验证码
- private function GenerateCheckCode():String
- {
- //初始化
- var ran:Number;
- var number:Number;
- var code:String;
- var checkCode:String ="";
- //生成四位的随机数,每循环一次生成一位
- for(var i:int=0; i<4; i++)
- {
- ran=Math.random();
- number =Math.round(ran*10000); //将随机数保留小数点后四位,例如:0.1234
- if(number % 2 == 0)
- code = String.fromCharCode(48+(number % 10)); // 数字0的ASCII码是:48
- else
- code = String.fromCharCode(65+(number % 26)) ; // 字母A的ASCII是: 65
- checkCode += code;
- }
- return checkCode;
- }
原文地址:
http://ntt.cc/2008/04/19/12-very-simple-basic-but-useful-function-source-in-flex.html <script type="text/javascript">
</script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script>