Flash: rest argument and array : how to?
I have an array of arguments like开发者_C百科:
params["username"]= "john";
params["age"] = "25";
params["country"] = "France";
params["something"] = something;
which is VARIABLE and I need to pass it as rest argument :
nc.call("myMethod", params["username"], params["age"], params["country"]... );
params has not fixed size.
Is that possible ???
Depending on what exactly you're trying to do, it seems like you can just say nc.call("myMethod", params), can't you?
Or are you looking for the rest syntax for AS3? In that case, this may help: http://www.sephiroth.it/weblog/archives/2006/06/actionscript_3_rest_parameter.php
But be careful, it looks like you're trying to make a NetConnection call there and so if you're actually calling for instance a PHP function then this won't work. The rest operator (...) is used when defining your method signatures in AS3.
If you just want to pass an array of parameters to a PHP function via AMFPHP or something like that, do what I said in my first sentence and simply pass the params object. On the PHP side you would treat it as an associative array ($params->username, $params->age, etc)
Hope that helps, and if it doesn't please be a little bit more clear about what it is you're trying to accomplish!
Cheers, myk
Focusing only on this one part of your question for now :
params has not fixed size.
Is that possible ???
Yes, it's absolutely possible when you treat the Array like it is a hash table. In fact, the Adobe livedocs specifically say you shouldn't do this. I'm guessing it's for reasons like these, to cut down on situations that arise from using it in a way that is ambiguous with a normal Object().
Anyway, Array.length ONLY returns a value between 0 and int.MAX_VALUE. If you've assigned a variable to an Array location that is not an integer between 0 and int.MAX_VALUE it will not be included in the .length property's return value.
精彩评论