I want to pass through configuration arguments to a class. These are all the optional vars that go into configuring the class - and should be able to run in any order.
at the moment i just pass through the optional vars the regular way. Supposing the constuctor was like the following:
private var _reqVar:String;
private var _optVar1:String;
private var _optVar2:String;
public function Constructor(reqVar:String, optVar1:String = "empty", optVar2:String = "empty){
// set the variable to equal the arguments here...
}
the problem with this is for the end user, where instantiating the class isnt particularly readable (especially when the argument list can grow quite large)
ideally i would like to pass the arguments though similar to this:
var instance:ClassType = new ClassType(reqVar, {width:100, height:100, speed:4, lives:3})
which again is fairly straight forward. where i stumble over are the following points:
- assigning the argument to the var of the same key (i know in php to reference a variable name from a key you can use $$key = $value, is there an equivalent in as3?)
- display an error (using the 'throw' method) for variable names not supported by the class
any help appreciated.