jedierikb
jedierikb

Reputation: 13079

object-reference as string?

In java, you can get a unique string for an object.

How can you do this in as3?

Upvotes: 4

Views: 3190

Answers (3)

back2dos
back2dos

Reputation: 15623

you can use this, to get a unique uint ... if you want to, convert it to a string ... :-P

package {
    import flash.utils.Dictionary;
    public class ObjectUIDUtil {
        private static var _uids:Dictionary = new Dictionary(true);
        private static var _cter:uint = 1;
        public static function getUID(obj:Object):uint {
            var ret:uint = _uids[obj];
            return (ret == 0) ? (_uids[obj] = _cter++) : ret;
        }
    }
}

please note, that this maybe is not even necessary, since flash.utils.Dictionary allows using objects as keys directly ...

greetz

back2dos

Upvotes: 4

enzuguri
enzuguri

Reputation: 828

in the same vain as the responses on the java thread, the is a unique ID generator as part of the flex SDK. This is found under mx.utils.UIDUtil, it works fairly simply.

var ID:String  = UIDUtil.createUID();

Hope this helps.

Upvotes: 3

Extrakun
Extrakun

Reputation: 19305

You can try using a third party hashing function (such as md5 or sha1). The hashcode for objects in Java (incidentally C#) is generated by a hashing function as well. Here's one I found on Google

Hope this helps.

Upvotes: 0

Related Questions