object-reference as string?

后端 未结 3 1674
日久生厌
日久生厌 2021-01-14 01:39

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

How can you do this in as3?

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-14 02:13

    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

提交回复
热议问题