let’s say I have a class:
public class SomeClass{
var name:String;
public function SomeClass(n){
name = n;
}
}
If I do var s:SomeClass = SomeClass("test");, it tries to convert a string to SomeClass. How do I prevent it from doing that?
Sorry I’m new to AS3.
You’re missing the
newoperator:var s:SomeClass = new SomeClass('test');Unless you use the
newoperator, there really isn’t a good way to create a Class member in ActionScript. There are some noteable exceptions, however. Array, XML, XMLList, int, uint, Number, String, and Object should almost never use their constructors.In AS, use of the class’s name as function is actually “Cast this to the class”. You can also do this through the
asoperator. The difference is thataswill return null on failure the other means will throw an error: