难以复制/扩展单例管理器类

发布于 2024-11-02 09:54:41 字数 404 浏览 2 评论 0原文

我想扩展或复制 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

饮湿 2024-11-09 09:54:41

这是关于 使用 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.

幼儿园老大 2024-11-09 09:54:41

您可能没有将您的属性声明为静态。 PopUpManager 使用所有静态方法 - 这就是为什么使用它时您使用如下语法:

PopUpManager.createPopUp(...

而不是

var popUpManager:PopUpManager = new PopUpManager();
popUpManager.createPopUp(...

这意味着在 PopUpManager 中声明的任何变量也需要是静态的,以便可以在类级别访问。

public static var windowCount:int

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:

PopUpManager.createPopUp(...

instead of

var popUpManager:PopUpManager = new PopUpManager();
popUpManager.createPopUp(...

This means that any variables declared in the PopUpManager need to also be static so as to be accessible at the class level.

public static var windowCount:int
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文