12 common flex function Codes

Source: Internet
Author: User
Tags rtrim
1. Copy content to system clipboard
    1. System. setclipboard (strcontent );

CopyCode

2. Copy an arraycollection

    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 (AC ).List);

Copy code

3. Open a new browser window

    1. NavigatetoURL (New URLRequest ('HTTP: // NTT. CC'), '_ blank ');

Copy code

4. Refresh the browser

    1. NavigatetoURL (New URLRequest ("Javascript: Location. Reload (); ")," _ Self ")

Copy code

5. Close your browser

    1. NavigatetoURL (New URLRequest ("javascript: window. Close ()"), "_ Self ");

Copy code

6. Set the background of the alert window to transparent

    1. Alert
    2. {
    3. Modaltransparency: 0.0;
    4. Modaltransparencyblur: 0;
    5. }

Copy code

7. Random color

    1. LBL. setstyle ('color', 0xffffff * Math. Random ());

Copy code

8. Clear space on the left of the substring

    1. Public Function ltrim (S: string): String
    2. {
    3. VaR I: 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. Return S. substring (I, S. Length );
    9. }

Copy code

9. Clear spaces on the right of a string

    1. Public Function rtrim (S: string): String
    2. {
    3. VaR I: 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. Return S. substring (0, I + 1 );
    9. }

Copy code

10. Clear spaces around the string

    1. Public Function trim (S: string): String
    2. {
    3. Return ltrim (rtrim (s ));
    4. }

Copy code

11. ObtainDataType

    1. Getqualifiedclassname (data)

Copy code

12. Generate a random string.

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

Copy code

Http://ntt.cc/2008/04/19/12-very... source-in-Flex. Html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.