How can I get an instance's “memory location” in ActionScript?

前端 未结 6 507
刺人心
刺人心 2020-12-03 01:01

FlexBuilder\'s debugger will show you the \"memory location\" (or, I can only assume, something roughly analogous) of any in-scope instance:

6条回答
  •  抹茶落季
    2020-12-03 01:33

    Diney Bomfim's solution worked like a charm. I wrapped this in a class named DebugUtils in a function named getObjectMemoryHash.

    package
    {
        public class DebugUtils
        {
            public static function getObjectMemoryHash(obj:*):String
            {
                var memoryHash:String;
    
                try
                {
                    FakeClass(obj);
                }
                catch (e:Error)
                {
                    memoryHash = String(e).replace(/.*([@|\$].*?) to .*$/gi, '$1');
                }
    
                return memoryHash;
            }
        }
    }
    
    internal final class FakeClass { }
    

    Then I could use this function from anywhere and trace it, like so:

    trace('myObj', DebugUtils.getObjectMemoryHash(myObj));
    

    Thanks so much for this answer!

提交回复
热议问题