问题描述
弹性生成器的调试器会告诉你的记忆区(或者,我只能假设,东西约analagous)任何范围的实例:
FlexBuilder's debugger will show you the "memory location" (or, I can only assume, something roughly analagous) of any in-scope instance:
不过,我想获得在code该信息(有点像Python的 ID
函数),这样我就可以很容易地追踪对象如何移动,通过了系统。例如,我可能有:
But I'd like to get this information in code (sort of like Python's id
function), so I could very easily trace how objects move through out the system. For example, I might have:
trace("Returning", id(foo));
然后在别的地方,我可以用:
Then somewhere else I could use:
trace("Using", id(foo));
要确保的code两个位都被处理相同的实例。
To make sure both bits of code are dealing with the same instance.
现在,我知道有很多AS类实现 IUID
接口......但也有一堆类,它们不(普通的旧数组和对象,例如),这样,才不会解决我的问题。
Now, I know that many AS classes implement the IUID
interface... But there are also a bunch of classes which don't (plain old arrays and objects, for example), so that wouldn't solve my problem.
我知道,我也可以在包装对象的一个ObjectProxy
,但是这将是不太理想的为好。
I realize that I could also wrap objects in an ObjectProxy
, but that would be less than ideal as well.
推荐答案
在真的我劝你不要使用这个太多了......这是非常昂贵。的Adobe需要创建一个本地函数返回这个给我们。
In realy I advise to you don't to use this too much... it is very expensive. Adobe need to create a native function to return this to us.
不过,现在...试试这个:
But, for now... try this:
您将需要引起强制转换,得到它!因为当你和强制转换,你会得到这样的错误:
You will need to cause a explicit coercion to get it!Because when you make and explicit coercion you get an Error like this:
TypeError: Error #1034:
Type Coercion failed: cannot convert Main@1c49d31 to flash.utils.ByteArray.
请注意,在这个错误你得到你想要的东西......在@ 1c49d31。该散列就像是在内存中分配一个ID。
Note that in this error you get what you want... the @1c49d31. This hash is like an ID in the memory allocation.
我做了很多的测试。这散列只是当你所谓的新改变(在C语言中等价于[...页头] INIT])和静态函数和静态属性,分配时有一点不同......反正...
I did a lot of tests. This hash just change when you call a "new" (in C languages is equivalent to [[... alloc] init]) and for static functions and static properties, the allocation occurs a little different... anyway...
备份到Flash,问题是我们没有一个直接的方式来获得这个哈希没有错误。
Backing to Flash, the problem is we don't have a direct way to get this hash without an Error.
但是,这是不是真的大问题。所有你需要的是使用一些尝试和catch像这样的:
But this is not a realy big problem. All that you need is to use some "try" and "catch"Like this:
try
{
ByteArray(anyObjectToKnowItAllocationHash);
}
catch (e:Error)
{
trace(e);
}
和瞧!您将获得哈希没有导致错误!在此之后我做了更refinated的方式...试试这个:
And voila!You will get the hash without result in an Error!After this I did a more refinated way... Try this:
var memoryHash:String;
try
{
FakeClass(anyObjectToKnowItAllocationHash);
}
catch (e:Error)
{
memoryHash = String(e).replace(/.*([@|\$].*?) to .*$/gi, '$1');
}
internal final class FakeClass { }
有关这方面的一个小说明:该fakeClass是要知道这会产生错误。该RegularEx pression是夺取最后的@ ......出现。因为对象和函数生成该错误不同的消息。而$是捕捉静态对象,类和函数,bacause他们没有一个@在内存中的散列函数和不同的区域在内存中。
A little explain about this:The fakeClass is to be sure about this will generate an Error.The RegularExpression is to capture the last @... that appear. Because Objects and Functions generate different messages on this Error. And the $ is to catch the Static Objects, Class and Functions, bacause they don't have an "@" in its memory hash and different zones in memory.
这一点code ++工程,所以没什么问题!现在我可以完成我正在做的工作,内存管理,弱引用和ID的基础上记忆一些伟大的引擎。
This little code works so fine to me! Now i can finish some great engines that i'm making that work with memory management, weak references and ID based on memory.
我希望这可以帮助你。
再见,祝你好运,我的朋友!
Bye, and good luck, my friend!
这篇关于我怎样才能得到一个实例的"存储地点"在ActionScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!