AS3比较两种功能 [英] AS3 Compare two functions
问题描述
我有一个静态数组,并在我的课,并通过这种方法我把一些功能在阵列中的静态方法。该方法被称为上的时间表,所以当我打两次架,将推动功能两次,依此类推。
I have a static Array and a static method in my class and via this method I push some functions in the array. The method is called on timeline so when I play the frame twice it will push the function twice and so on.
问: 如何检查是否函数存在和prevent重复? (很喜欢的addEventListener)
Question : How can I check if the function exists and prevent duplication? ( it is like addeventlistener )
推荐答案
短版:不要在时间轴上的code
short version: don't code on the timeline.
长版:如果你是幸运的功能是一样的,所以它可以使用 ==
运营商对它们进行比较。但如你编码在时间轴上,也有可能是相同的函数的几个实例,所以这将无法工作。你可以保存一个静态布尔表示,如果你已经添加了。
long version: if you're lucky the functions would be the same, so it's possible to compare them using the ==
operator. but as you're coding on the timeline, there may be several instances of the same function, so this won't work. You could save a static Boolean indicating if you've already added it.
但!开始编码类,它会为你节省很多的麻烦,从长远来看,并给你更好的答案在这里对堆栈溢出 - 这有点像问一个5星级厨师,为什么你只,加水和 - shake- togehter蛋糕并没有变成非常大的。
BUT! Start coding in classes, it will save you a lot of trouble in the long run, and give you much better answers here on Stack Overflow -- it's kinda like asking a 5 star chef why your only-add-water-and-shake-togehter-cake didn't turn out very great.
这篇关于AS3比较两种功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!