Friday, September 12, 2008

Variable constructor arguments in AS3

The new Flex SDK (for Flash Player 10) allows two arguments in
the constructor of NetStream although second is optional,
but the old SDK (for Flash Player 9) allows only one. The following
piece of code tries to allocate NetStream, but cannot be compiled
in old SDK. How would you change it so that it can compile and work
in both old and new SDK?

if (flashMajorVersion >= 10)
ns = new NetStream(connection, id);
else
ns = new NetStream(connection);

1 comment:

Kundan said...

One way to avoid the compiler error is to create the object from an anonymous class:

var c:Class = NetStream;
ns = new c(connection, id);