本文和大家重点讨论一下一些常用的Flex源代码,通过这些源代码的学习我们会对Flex代码的认识会更加熟悉,在以后的使用的过程中可以信手拈来。
12条常用的Flex源代码
1.复制内容到系统剪贴板
Java代码
- System.setClipboard(strContent);
- System.setClipboard(strContent);
2.复制一个ArrayCollectionFlex源代码
Java代码
- //dummysolution(well,itworks)
- varbar:ArrayCollection=newArrayCollection();
- foreach(vari:Objectinac){
- bar.addItem(i);
- }
- //fantastic!//
- varbar:ListCollectionView=newListCollectionView(ListCollectionView(ac).list);
- //dummysolution(well,itworks)varbar:ArrayCollection=newArrayCollection();
- foreach(vari:Objectinac){bar.addItem(i);}
- //fantastic!//varbar:ListCollectionView=newListCollectionView(ListCollectionView(ac).list);
3.打开一个新浏览器窗口
Java代码
- navigateToURL(newURLRequest('http://52friends.com'),'_blank');
- navigateToURL(newURLRequest('http://52friends.com'),'_blank');
4.刷新浏览器Flex源代码
Java代码
- navigateToURL(newURLRequest("javascript:location.reload();"),"_self")
- navigateToURL(newURLRequest("javascript:location.reload();"),"_self")
5.关闭浏览器Flex源代码
Java代码
- navigateToURL(newURLRequest("javascript:window.close()"),"_self");
- navigateToURL(newURLRequest("javascript:window.close()"),"_self");
#p#6.设置Alert窗口的背景为透明
Java代码
- Alert
- {
- modalTransparency:0.0;
- modalTransparencyBlur:0;
- }
- Alert{modalTransparency:0.0;modalTransparencyBlur:0;}
7.取随机颜色Flex源代码
Java代码
- lbl.setStyle('color',0xffffff*Math.random());
- lbl.setStyle('color',0xffffff*Math.random());
8.清除子串左侧空格
Java代码
- publicfunctionLTrim(s:String):String
- {
- vari:Number=0;
- while(s.charCodeAt(i)==32||s.charCodeAt(i)==13||s.charCodeAt(i)==10||s.charCodeAt(i)==9)
- {
- i++;
- }
- returns.substring(i,s.length);
- }
- publicfunctionLTrim(s:String):String{vari:Number=0;
- while(s.charCodeAt(i)==32||s.charCodeAt(i)==13||s.charCodeAt(i)==10||
- s.charCodeAt(i)==9){i++;}returns.substring(i,s.length);}
9.清除字串右侧空格Flex源代码
Java代码
- publicfunctionRTrim(s:String):String
- {
- vari:Number=s.length-1;
- while(s.charCodeAt(i)==32||s.charCodeAt(i)==13||s.charCodeAt(i)==10||s.charCodeAt(i)==9)
- {
- i--;
- }
- returns.substring(0,i+1);
- }
- publicfunctionRTrim(s:String):String{vari:Number=s.length-1;
- while(s.charCodeAt(i)==32||s.charCodeAt(i)==13||s.charCodeAt(i)==10
- ||s.charCodeAt(i)==9){i--;}returns.substring(0,i+1);}
#p#10.清除字串左右的空格
Java代码
- publicfunctionTrim(s:String):String
- {
- returnLTrim(RTrim(s));
- }
- publicfunctionTrim(s:String):String{returnLTrim(RTrim(s));}
11.获取数据类型Flex源代码
Java代码
- getQualifiedClassName(data)
- getQualifiedClassName(data)
12.生成随机字符串.
Java代码
- privatefunctionGenerateCheckCode():String
- {
- //init
- varran:Number;
- varnumber:Number;
- varcode:String;
- varcheckCode:String="";
- //get4radom
- for(vari:int=0;i<4;i++)
- {
- ran=Math.random();
- number=Math.round(ran*10000);//getresultlike0.1234
- if(number%2==0)
- code=String.fromCharCode(48+(number%10));//0'sASCIIcodeis48
- else
- code=String.fromCharCode(65+(number%26));//A'sASCIIcodeis65
- checkCode+=code;
- }
- returncheckCode;
- }
- privatefunctionGenerateCheckCode():String{//initvarran:Number;
- varnumber:Number;varcode:String;varcheckCode:String="";
- //get4radomfor(vari:int=0;i<4;i++){ran=Math.random();number=Math.round(ran*10000);
- //getresultlike0.1234if(number%2==0)code=String.fromCharCode(48+(number%10));
- //0'sASCIIcodeis48elsecode=String.fromCharCode(65+(number%26));
- //A'sASCIIcodeis65checkCode+=code;}returncheckCode;}
【编辑推荐】
- 解读开源Flex源代码使用
- 解读Flex源代码使用,就像打开的糖果箱
- Flex及FlexBuilder2.0开发环境详解
- FlexBuilder3.0与Eclipse3.4的***结合
- Flex内存泄露解决方法和内存释放优化原则