I have a Class as follow:
class com.flightstatus.SpecificationFlight
{
public var Airline:Airline;
public var FlightNumber:String;
public var SearchCodeshares:Boolean;
public var SearchCodesharesSpecified:Boolean;
public var TailNumber:String;
}
Now I want to create a array of above type like below: var myArr:SpecificationFlight = new Array();
This type is very crucial as it will be sent over webservice.
Is this possible in AS3 ?If so , can I import only this feature to AS2 and use it.
Your code is AS2, not AS3, in AS3 you cannot declare a class using periods in the name, instead packages are used. (Technically, this is not precise, you could've have periods in the name if you altered the bytecode after it was compiled, but I doubt you meant that).
AS2 has no typed arrays, i.e. it has only one Array class and it can contain objects of any type. However, you can define a __resolve(x)
method for your custom class and let only objects of certain type be returned from yourClassInstance[x]
code. Unfortunately, you cannot control the type of an object being assigned to yourClassInstance[x]
.
In AS3 there is a Vector.<T>
class since Flash player 10. This class is used to create vectors of certain type, obviously.
In the Haxe language, which can compile to AS2 and AS3 there are typed arrays, but they are enforced on the language (compiler) level, if you then access the compiled code through reflection or through some other code not compiled with Haxe, then arrays are still untyped (pretty much like generics work in Java).
PS. It is extremely counterintuitive to use Pascal case for variables' names in either variant of AS, class fields are usually camel-cased (even the code highlighter assumed those are class names, not variable names). Using public variable us usually a bad idea too, but it is not necessarily bad, depends on the context, yet I'd certainly be alarmed.