tags:

views:

670

answers:

2

Given the following Flash method:

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

How do I ensure that ExternalInterface.call() interprets args in its expanded form? Right now, if I pass a list into "args", that list gets interpreted as a single argument of type "Object[]" by ExternalInterface.call(). When the arguments reach Java, I have no way of differentiating between multiple arguments separated by commas versus a single argument containing commas as part of its value.

+1  A: 

I found an answer on IRC :)

function sendToJava(name:String, ... args)
{
  // See Array.unshift()
  args.unshift("sendCommand", name);

  // See Function.apply()
  ExternalInterface.call.array(null, args);
}
Gili
+3  A: 

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 "array" to "apply"

Anyways, thanks a ton for posting this. You're a lifesaver!

Micah
You're welcome. Thanks for the correction :)
Gili