The following example shows you how you can create a unique indentifier (UID) with Flex using the UIDUtil class in the mx.utils package. By calling the static UIDUtil.createUID() method, you can easily create a hexadecimal string in the following format: “XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX”.
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/11/01/creating-unique-identifiers-with-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
creationComplete="generateUID();">
<mx:Script>
<![CDATA[
import mx.utils.UIDUtil;
private function generateUID():void {
lbl.text = UIDUtil.createUID();
}
]]>
</mx:Script>
<mx:ApplicationControlBar dock="true">
<mx:Button id="btn"
label="Create UID"
click="generateUID();" />
</mx:ApplicationControlBar>
<mx:Label id="lbl"
fontSize="20"
selectable="true" />
</mx:Application>
View source is enabled in the following example.
Note that the generated unique identifier is not a globally unique value, but rather a pseudo-random number generator based on the current time.





I’m loving flexexamples. With about 3/4 of the things I google, I end up here.
So an overdue comment: thanks a lot.
N.