Home > actionscript, development, flash > Actionscript 3 GUID – Generating unique IDs for users in AS3

Actionscript 3 GUID – Generating unique IDs for users in AS3

April 28th, 2009 Leave a comment Go to comments

Have you ever needed to generate a unique ID for users? I’m sure you have. But, have you ever had to create a unique ID for users without referencing the other user IDs (checking for duplicates)? I ran into this issue and discovered globally unique identifier (GUID for short). This is something constantly used in the programming world, but not something I needed in the actionscript world, until now. Being a Flash developer who comes from a design background, I am constantly catching up with the tips and tricks of the hard core programming community.

To give you a little background on a GUID, it is a reference number that is randomly generated. The beauty of a GUID is that the total number of unique keys (2128 or 3.4×1038) is so large that the probability of the same number being generated twice is infinitesimally small.

Since this instantly became something I could use in future projects, I decided to create an actionscript 3 class. I used the AS2 class created by Meychi.com (which is no longer up for some reason) as a base for the GUID equation.

To make sure my fellow Flash developers have the tools they need to create GUIDs, I have uploaded this file for download.

You can use this class by calling the “GUID.create()” function.

  1. Alrick
    May 9th, 2009 at 14:16 | #1

    Thanks for the class.

  2. September 27th, 2009 at 15:25 | #2

    Thanks a lot. You saved me couple of hours of work! :)

  3. Ralph
    October 7th, 2009 at 15:17 | #3

    Good job, buy this is a utility class and you shouldn’t be extending Sprite as a base class unless you are implying a GUID is a sprite. Only trying to help.

  4. zutroy
    November 19th, 2009 at 10:08 | #4

    Just a note if you are using flex you can simply use UIDUtil:

    import mx.utils.UIDUtil;
    UIDUtil.createUID();

  5. AHernandez
    November 20th, 2009 at 10:55 | #5

    Very nice work man. This was really helpful.

  6. December 3rd, 2009 at 13:31 | #6

    awesome bro thanks!

  7. SmartGlorious
    December 15th, 2009 at 02:07 | #7

    Thanks man ! it’s very helpful

  8. Norbz
    February 18th, 2010 at 08:55 | #8

    Just saved me a couple of hours. Thx for sharing :)

  9. Frank Z
    March 23rd, 2010 at 10:15 | #9

    Thanks! I was used to Flex which had it built in and couldn’t find the Flash equivalent. Your class fits the bill! Well done!

  10. sideDoor
    April 13th, 2010 at 22:13 | #10

    You bad-ass, thanks for sharing this!

  11. Dan Rostron
    July 13th, 2010 at 07:43 | #11

    Legend!!!

  1. July 8th, 2010 at 08:14 | #1