Flex中12个简单实用的小技巧
PLAIN TEXT >> ACTIONSCRIPT:
-
//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 );
PLAIN TEXT >> ACTIONSCRIPT:
-
navigateToURL(new URLRequest("javascript:location.reload();"), "_self");
PLAIN TEXT >> ACTIONSCRIPT:
-
// 原文采用循环查找字符然后用 substring 截取字符的方式
-
// 这种方式代码多, 效率低, 这里就不列出原文的代码了
-
// 下面是我用正则实现的(包括下面的 rtrim)
-
private function ltrim(_s:String):String
-
{
-
return _s.replace(/^\s+/, '');
-
}
PLAIN TEXT >> ACTIONSCRIPT:
-
private function rtrim(_s:String):String
-
{
-
return _s.replace(/\s+$/, '');
-
}
PLAIN TEXT >> ACTIONSCRIPT:
-
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