Flex中12个简单实用的小技巧

  • 复制内容到剪贴板
    PLAIN TEXT >> ACTIONSCRIPT:
    1. System. setClipboard (strContent );

     

  • 复制一个 ArrayCollection
    PLAIN TEXT >> ACTIONSCRIPT:
    1. //dummy solution( well, it works )
    2. var bar:ArrayCollection = new ArrayCollection ( );
    3. for each ( var i: Object in ac ) {
    4. bar. addItem ( i );
    5. }
    6. // fantastic ! //
    7. var bar:ListCollectionView = new ListCollectionView ( ListCollectionView ( ac ). list );

     

  • 打开 URL
    PLAIN TEXT >> ACTIONSCRIPT:
    1. navigateToURL ( new URLRequest ( 'http://phpz.org/' ), '_blank' );

     

  • 刷新页面
    PLAIN TEXT >> ACTIONSCRIPT:
    1. navigateToURL ( new URLRequest ( "javascript:location.reload();" ), "_self" );

     

  • 关闭浏览器
    PLAIN TEXT >> ACTIONSCRIPT:
    1. navigateToURL ( new URLRequest ( "javascript:window.close()" ), "_self" );

     

  • 设置 Alert 窗口透明背景
    PLAIN TEXT >> ACTIONSCRIPT:
    1. Alert
    2. {
    3. modalTransparency: 0. 0;
    4. modalTransparencyBlur: 0;
    5. }

     

  • 设置随机颜色
    PLAIN TEXT >> ACTIONSCRIPT:
    1. lbl. setStyle ( 'color', 0xffffff * Math. random ( ) );

     

  • 删除字符串左空白字符
    PLAIN TEXT >> ACTIONSCRIPT:
    1. // 原文采用循环查找字符然后用 substring 截取字符的方式
    2. // 这种方式代码多, 效率低, 这里就不列出原文的代码了
    3. // 下面是我用正则实现的(包括下面的 rtrim)
    4. private function ltrim (_s: String ): String
    5. {
    6. return _s. replace (/^\s+/, '' );
    7. }

     

  • 删除字符串右空白字符
    PLAIN TEXT >> ACTIONSCRIPT:
    1. private function rtrim (_s: String ): String
    2. {
    3. return _s. replace (/\s+$/, '' );
    4. }

     

  • 删除字符串两侧空白字符
    PLAIN TEXT >> ACTIONSCRIPT:
    1. private function trim (_s: String ): String
    2. {
    3. return ltrim (rtrim (_s ) );
    4. }

     

  • 取得数据类型
    PLAIN TEXT >> ACTIONSCRIPT:
    1. getQualifiedClassName ( data );

     

  • 生成验证码
    PLAIN TEXT >> ACTIONSCRIPT:
    1. private function GenerateCheckCode ( ): String
    2. {
    3. //init
    4. var ran: Number;
    5. var number: Number;
    6. var code: String;
    7. var checkCode: String = "";
    8. //get 4 radom
    9. for ( var i: int= 0; i< 4; i++ )
    10. {
    11. ran= Math. random ( );
    12. number = Math. round (ran* 10000 ); //get result like 0.1234
    13. if ( number % 2 == 0 )
    14. code = String. fromCharCode ( 48+ ( number % 10 ) ); //0's ASCII code is 48
    15. else
    16. code = String. fromCharCode ( 65+ ( number % 26 ) ) ; // A's ASCII code is 65
    17. checkCode += code;
    18. }
    19. return checkCode
  • 你可能感兴趣的:(Flex)