我在 AS3 中创建了一个类来表示复数。它不继承任何东西。我怎样才能从例如数字? IE。我想要这个:
5 as Complex
与此相同:
new Complex(5);
我可以在我的类(class)中加入神奇的 cast() 函数吗?
最佳答案
恐怕不会。 Number
是与您的 Complex
类无关的类型。您将收到的只是:
1067: Implicit coercion of a value of type Number to an unrelated type Complex
我唯一能想到的就是做这样的事情:
asComplex(5);
public function asComplex(num:Number):Complex
{
return new Complex(num);
}
但不确定这有什么意义。
关于actionscript-3 - 如何在 Actionscript 3 中为我自己的类实现转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7076292/