难以复制/扩展单例管理器类
我想扩展或复制 PopUpManager 类以添加跟踪窗口数量的功能。 我只想在添加窗口时添加一个简单的 windowCount++ ,在删除窗口时添加 windowCount-- 。
问题是 PopUpManager 是一个 Singleton 类...我无法通过扩展它来使其正常工作。现在我尝试从 PopUpManager.as 文件复制代码,并将我的变量添加到其函数的末尾。它似乎不起作用,因为它说我的属性未定义,即使它们是在构造函数上方声明的。
我想我必须复制 PopUpManagerImpl.as ,因为这似乎是大部分业务所在(PopUpManagerImpl extends EventDispatcher Implements IPopUpManager
),这将允许我访问该变量吗?我应该忽略管理器并将其放在实现类中吗?
I want to extend or copy the PopUpManager class to add the ability to keep track of the number of windows.
I just want to add a simple windowCount++ when a window is added and windoCount-- when it's removed.
the problem is PopUpManager is a Singleton class... I wasn't able to make it work properly by extending it. And now I have tried to copy the code from the PopUpManager.as file and just add my variable to the end of its functions. It doesn't seem to be working though since it says my properties are undefined even though they are declared above the constructor.
I am thinking I would have to make a copy of the PopUpManagerImpl.as since that's wehre it seems much of the business resides (PopUpManagerImpl extends EventDispatcher implements IPopUpManager
) would that allow me to have access to the variable? and should I ignore the manager and just put it in the implementation class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是关于 使用 Flex Singleton 寄存器,当我发现自己处于同样的情况时,它帮助了我。
我希望你也能从中得到启发。
here is a link about Using the Flex Singleton register, which helped me out when finding myself in the same situation.
I hope you can inspire from that too.
您可能没有将您的属性声明为静态。 PopUpManager 使用所有静态方法 - 这就是为什么使用它时您使用如下语法:
而不是
这意味着在 PopUpManager 中声明的任何变量也需要是静态的,以便可以在类级别访问。
You likely didn't declare yours properties as static. The PopUpManager uses all static methods - this is why working with it you use syntax like:
instead of
This means that any variables declared in the PopUpManager need to also be static so as to be accessible at the class level.