-
Vector as function default parameter
Hi everyone.
Does anyone know what is the syntax to use for a function's default parameter when it's a Vector?
You can easily create a default value for an int or Number or even an Array, but what about a Vector?
Thanks
-
I don't think you can do that easily, since the default value must be statically determinable. I'm mildly surprised it works with arrays.
The workaround would be to make the default value null, and then check for null inside the function and use a runtime determined default value at that time.
Code:
function someFunction(arg:Vector.<Number> = null):void{
if (null == arg){
arg = Vector.<Number>([1, 3, 5, 7]);
}
//do stuff
}
-
Thanks!
I knew it was not possible directly, what a shame! X(
Thanks for your workaround suggestion though. I'll see what I can do with that.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|