12个Flex常用功能代码
1。复制内容到Flex系统剪贴板
System.setClipboard(strContent);
2。复制一个ArrayCollection
//dummysolution(well,itworks)
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。Flex打开一个新浏览器窗口
navigateToURL(newURLRequest('http://ntt.cc'),'_blank');
4。刷新浏览器
navigateToURL(newURLRequest("javascript:location.reload();"),"_self")
5。关闭浏览器
navigateToURL(newURLRequest("javascript:window.close()"),"_self");
6。Flex设置Alert窗口的背景为透明
Alert
{
modalTransparency:0.0;
modalTransparencyBlur:0;
}
7。取随机颜色
lbl.setStyle('color',0xffffff*Math.random());
8。清除子串左侧空格
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字符串右侧空格
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);
}
10。清除Flex字符串左右的空格
publicfunctionTrim(s:String):String
{
returnLTrim(RTrim(s));
}
11。获取数据类型
getQualifiedClassName(data)
12。生成随机Flex字符串。
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+(number26));
//A'sASCIIcodeis65
checkCode+=code;
}
returncheckCode;
}