12條有用的as代碼

來源:互聯網
上載者:User

一些常用到的例如剪貼簿操作,視窗操作字串等.
1.複製內容到系統剪貼簿

1 System.setClipboard(strContent);

2.複製一個ArrayCollection

1
2
3
4
5
6
7
//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 );

3.開啟一個新瀏覽器視窗

1 navigateToURL(new URLRequest("http://www.5ga.cn"), "_blank");

4.重新整理瀏覽器

1 navigateToURL(new URLRequest("javascript:location.reload();"),"_self");

5.關閉瀏覽器

1 navigateToURL(new URLRequest("javascript:window.close()"),"_self");

6.設定Alert 視窗的背景為透明

1
2
3
4
Alert {
    modalTransparency:0.0;
    modalTransparencyBlur:0;
}

7.取隨機顏色

1 lbl.setStyle('color', 0xffffff*Math.random());

8.清除子串左側空格

1
2
3
4
5
6
7
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);
}

9.清除字串右側空格

1
2
3
4
5
6
7
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);
}

10.清除字串左右的空格

1
2
3
public function Trim(s : String):String {
    return LTrim(RTrim(s));
}

11.擷取資料類型

1 getQualifiedClassName(data) ;

12.產生隨機字串.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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;
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.