[flex] 12个Flex常用功能代码

1. Copy content to clipboard

System.setClipboard(strContent);


2. Clone an 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 ); 


3. Open URL

navigateToURL(new URLRequest('http://ntt.cc'), '_blank');


4. Page reload

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


5. Close browse

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


6. Set the background alpha to transparent on Alert window

Alert 
    { 
    modalTransparency:0.0;  
    modalTransparencyBlur:0;
    }


7. Set random color

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


8. Trim left of white space

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. Trim right of white space

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. Trim left and right of white space

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


11. get data type

getQualifiedClassName(data)


12. Generate check digits

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

你可能感兴趣的:(JavaScript,java,Flex)