12 个简单易用的 Flex 功能

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 打开一个新地址:

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

{

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

}

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: