在 AS3 中创建顶级类的副作用?

发布于 2024-10-07 23:41:00 字数 125 浏览 9 评论 0原文

除了可能的类名冲突之外,在 ActionScript 3 中创建名称如“Tracer”的顶级(无包名称)类还会有任何问题或副作用吗?我想将这样的类保留为顶级,这样我就不必在代码中使用 import 语句。到目前为止我还没有遇到任何问题。

Besides possible class name collisions, would there be any problems with or side effects of creating a top-level (no package name) class with a name like "Tracer" in ActionScript 3? I want to keep such a class top-level so I don't have to use import statements for it in my code. So far I haven't had any problems.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

浅浅 2024-10-14 23:41:00

最佳实践是在适当的时候使用包。如果您正在构建的是一个实用程序,最好将其放入 util 包中,而不是将其保留在顶层。

如果您正在开发可以被视为核心功能的东西,那么实现顶级成员就没有问题。

最后要规划的是可重用性。如果您知道您正在构建永远不会重用的东西(最终实现类),请不要太担心它是顶级类,因为一旦您编译了 swf,它就应该继续工作。

相反,如果您正在开发一项功能并希望将其作为框架重用,那么您最好将其作为框架级成员未来发展的灵活性。

The best practice is to use a package whenever appropriate. If what you're building is a utility, it's better to put it in a util package than leave it top level.

If you're developing something that could be seen as core functionality, there's no issue in implementing a top-level member.

The last thing to plan for is reusability. If you know you're building something that you're never going to reuse (final implementation classes), don't worry too much about having it be a top-level class as it should continue to work once you've compiled the swf.

If, instead, you're making a feature that you'd like to reuse as a framework, you're probably better off putting it as a framework-level member for flexibility with future development.

我很OK 2024-10-14 23:41:00

zzzzBov 的回答是个好建议。但要明确回答您的问题:可能的名称冲突确实是您正在做的事情的唯一副作用。

zzzzBov's answer is good advice. But to answer your question explicitly: possible name collisions are indeed the only side effect to what you're doing.

眉黛浅 2024-10-14 23:41:00

我即将描述我想到的一个可能的问题,我将其发布是因为从技术上讲这不是名称冲突(字母大小写不同)。

假设您有一个顶级类,除了字母大小写不同之外,它共享顶级包的名称(例如“flash”、“fl”、“com”或自定义包)。如果您输入类似“var x:”的内容,然后尝试输入完全限定的类名...那么 FlashDevelop 等程序中的代码完成引擎将默认为您的“Flash”类(如果存在),而不是您可能正在尝试输入“flash”包。这是非常令人恼火的,主要是因为它以这种方式运行有点有意义,而且它有点必须代码完成一个或另一个:(

所以要非常小心地命名顶级类,其拼写与包相同名称(顶级或其他)。

I'm about to describe a possible issue I thought of, and I'm posting it because it's not technically a name collision (the letter-case is different).

Suppose you have a top-level class that shares the name of a top-level package aside from a difference in letter-case (for example "flash", "fl", "com", or a custom package). If you type something like "var x:" and then try to type a fully qualified classname... then the code-completion engine in a program like FlashDevelop will default to your "Flash" class (if it exists), rather than the "flash" package you may be trying to type. It's extremely irritating, mainly because it makes a little bit of sense that it functions that way, and it kinda has to code-complete one or the other :(

So be very careful naming top-level classes something that's spelled the same as a package name (top-level or otherwise).

以为你会在 2024-10-14 23:41:00

我在自定义包中有一个名为 Vector 的类,并使用 flash 9,一切都很完美,直到我不得不使用 flash 10 来保存文件,问题是我无法创建 Vector 类的实例,因为错误 TypeError:错误#1007:尝试在非构造函数上实例化。解决这个问题的唯一方法是更改​​ AS 类的名称,幸运的是后端类的绑定与我的 Java 类 Vector 兼容。

似乎 flash 没有处理顶级类的类包。

我希望这对某人有帮助,即使这个问题的日期已经是两年前了。

I had a class named Vector in a custom package and using flash 9 and everything worked perfect until I had to use flash 10 to save files the problem was that I wasn't able to create an instance of my class Vector due with error TypeError: Error #1007: Instantiation attempted on a non-constructor. The only way to fix it was changing the name of the AS class, fortunately the binding for backend class works with my Java's class Vector.

Seems that flash isn't taking care of class package for top level classes.

I hope this helps somebody, even when the date of this question is almost 2 years ago.

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