12 very simple,basic but useful function source in Flex

No.1 Copy content to clipboard:

  1. System.setClipboard(strContent);

No.2 Clone an ArrayCollection:

  1. //dummy solution( well, it works )
  2. varbar:ArrayCollection = new ArrayCollection();
  3. foreach ( var i:Object in ac ){
  4. bar.addItem(i );
  5. }
  6. // fantastic ! //
  7. varbar:ListCollectionView = new ListCollectionView( ListCollectionView( ac ).list );

No.3 Open URL:

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

No.4 Page reload:

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

No.5 Close browse:

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

No.6 Set the background alpha to transparent on Alert window:

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

No.7 Set random color:

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

No.8 Trim left of white space

  1. public function LTrim(s : String):String
  2. {
  3. vari : Number = 0;
  4. while(s.charCodeAt(i) == 32 || s.charCodeAt(i) == 13 || s.charCodeAt(i) == 10 || s.charCodeAt(i) == 9)
  5. {
  6. i++;
  7. }
  8. returns.substring(i,s.length);
  9. }

No.9 Trim right of white space

  1. public function RTrim(s : String):String
  2. {
  3. vari : Number = s.length - 1;
  4. while(s.charCodeAt(i) == 32 || s.charCodeAt(i) == 13 || s.charCodeAt(i) == 10 ||s.charCodeAt(i) == 9)
  5. {
  6. i--;
  7. }
  8. returns.substring(0,i+1);
  9. }

No.10 Trim left and right of white space

  1. public function Trim(s : String):String
  2. {
  3. returnLTrim(RTrim(s));
  4. }

No.11 get data type:

  1. getQualifiedClassName(data)

No.12 Generate check digits

  1. private function GenerateCheckCode():String
  2. {
  3. //init
  4. varran:Number;
  5. varnumber:Number;
  6. var code:String;
  7. varcheckCode:String ="";
  8. //get 4 radom
  9. for(vari: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. returncheckCode;
  20. }

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