How to pass varargs to the method as an extended list?

Given the following Flash method:

function sendToJava(name:String, ... args) { ExternalInterface.call("sendCommand", name, args); } 

How to ensure that ExternalInterface.call () interprets args in its extended form? Right now, if I pass the list to "args", this list is interpreted as a single argument of type "Object []" by ExternalInterface.call (). When the arguments reach Java, I cannot distinguish between multiple arguments separated by commas, against a single argument containing commas as part of its value.

+3
source share
2 answers

One small typo. It should be:

 function sendToJava(name:String, ... args) { // See Array.unshift() args.unshift("sendCommand", name); // See Function.apply() ExternalInterface.call.apply(null, args); } 

Just change the "array" to "apply"

Anyway, thanks a ton for posting this. You are the rescuer!

+5
source

I found an answer to IRC :)

 function sendToJava(name:String, ... args) { // See Array.unshift() args.unshift("sendCommand", name); // See Function.apply() ExternalInterface.call.array(null, args); } 
+1
source

All Articles