Actionscript 3 - 将自定义类作为参数传递给未构造参数类的自定义类

发布于 2024-11-15 20:45:11 字数 841 浏览 0 评论 0原文

您好,提前致谢, 我有一个从我的主类构建的自定义类。在自定义类中,它有另一个作为参数传入的自定义类。我想严格输入参数变量,但是当我这样做时,“该类型不是编译类型常量等”。 据我了解,这是因为用作参数的自定义类尚未构建。 当我使用变量类型(*)来输入参数时,这一切都有效。 我怀疑这是一个设计缺陷,因为我使用了不正确的设计模式。它实际上是旧代码,是从不完全熟悉 oop 概念和设计模式的其他人那里收到的一个大型项目。 我已经考虑过在主类中为参数化类使用虚拟构造函数,但传入的类也采用自定义类(本身带有参数构造函数)。我正在考虑使用...(其余),以便自定义类的参数是可选的。 还有其他方法可以控制类的构建顺序吗?其余的变量会起作用吗? 谢谢

(编辑) 在构造函数或另一个函数中的 main.as 中

varparameter1:customclass2;

自定义类1(参数1);

在 customclass1 构造函数中:

public function customclass1(parameter1:customclass2) { ....

Flash抱怨当我在参数中使用数据类型customclass 2时找不到编译类型。当我使用变量数据类型 * 或省略数据类型(无论如何默认为 * )时,它不会抱怨。我认为这是因为 customclass2 尚未构造,因此编译器无法使用。 或者,我还没有将 customclass2 的路径添加到编译器中,但我相当确定我已经排除了这种情况。 代码有 10,000 多行,但整体运行良好。我重写只是为了优化编译器 - 严格的数据输入、错误处理等。如果我发现继承等可用作选项的情况,那么我将使用它,但它已经分为类(至少在主体)。这只是为了让我自己安心,并维持严格的数据类型策略,以便编译器优化更有效地工作。 谢谢

Hi and thanks in advance,
I have a custom class being constructed from my main class. In the custom class it has another custom class that is passed in as a parameter. I would like to strictly type the parameter variable but when I do, 'the type is not a compile type constant etc'.
This, I understand, is because the custom class used as a parameter has not yet been constructed.
It all works when I use the variable type ( * ) to type the parameter.
I suspect this is a design flaw, in that I am using an incorrect design pattern. It is actually hand-me-down code, having received a large project from someone else who is not entirely familiar with oop concepts and design patterns.
I have considered using a dummy constructor for the parametered class in my main class but the passed in class also takes a custom class (itself with a parametered constructor). I am considering using ... (rest) so that the custom classes' parameters are optional.
Is there any other way to control the order of construction of classes? Would the rest variables work?
Thanks

(edit)
in main.as within the constructor or another function

var parameter1:customclass2;

customclass1(parameter1);

in customclass1 constructor:

public function customclass1(parameter1:customclass2)
{
....

Flash complains that the compiled type cannot be found when I use the data type customclass 2 in the paramater. It does not complain when I use the variable data type * or leave out the data type (which then defaults to * anyway). I reason that this is because customclass2 has not yet been constructed and is therefore not available to the compiler.
Alternatively, I have not added the path of customclass2 to the compiler but I am fairly certain I have ruled this out.
There are over 10,000 lines of code and the whole thing works very well. I am rewriting simply to optimise for the compiler - strict data typing, error handling, etc. If I find a situation where inheritance etc is available as an option then I'll use it but it is already divided into classes (at least in the main part). It is simply for my own peace of mind and to maintain a policy of strict data typing so that compiler optimization works more efficiently.
thnx

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

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

发布评论

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

评论(1

凡尘雨 2024-11-22 20:45:11

我还没有将 customclass2 的路径添加到编译器中,但我相当确定我已经排除了这一点。

那么,如果您没有在任何地方编写该类,编译器可以做什么?当然会窒息。您要么必须编写 CustomClass 类文件,要么只使用“thing:Object”或“thing:Asteriks”。当您使用“*”类类型时,它不会抱怨,因为它可以是任何数组、字符串、先前声明的类。但是,当您指定不存在的内容时,无论参数声明的顺序如何,它都会被阻塞。

I have not added the path of customclass2 to the compiler but I am fairly certain I have ruled this out.

So if you don't have the class written anywhere what can the compiler do ? It is going to choke of course. You either have to write the CustomClass class file or just use "thing:Object" or "thing:Asteriks". It's not going to complain when you use the "*" class type because it could be anything an array, string, a previously declared class. But when you specify something that doesn't exists it will just choke, regardless of the order the parameters are declared in.

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