In our application, sometimes we need to keep the same object in several different places. Of course, we can create our own logic to produce a unique id for each objects. But Flex has contained a convinient way for us to complete this type of task.
First of all, we need to implement the mx.core.IUID interface, and then, we can use mx.core.UIDUtil.createUID function to generate the unique id for our object in our class’s constructor. This method will create a 32 bit hex string like:
E4509FFA-3E61-A17B-E08A-705DA2C25D1C
Here is the example:
package {
import mx.core.IUID;
import mx.utils.UIDUtil;
[Bindable]
public class Message implements IUID {
public var messageStr:String;
public var fromID:String;
private var _uid:String;
public function Message() {
_uid = UIDUtil.createUID();
}
public function get uid():String {
return _uid;
}
public function set uid(value:String):void {
// Since we'vealreadycreatedtheid,there's
//nothing to be done here, but the method is
//required by the IUID interface
}
}
}
