Whenever you need to pass a variable number of arguments, check Function.apply().It generally will be the answer to your problem!
If I understood your problem correctly, this should do what you want: var args:Array = [0,1,2,3,4,5]; var jsFunctionName:String = "someJsFunction"; var parameters:Array = args && args.length > 0 ? [jsFunctionName].concat(args) : [jsFunctionName]; ExternalInterface.call.apply(null,parameters); Since ExternalInterace::call is static, the first param (the "this" context object) is null. The parameters are passed to the function as if you had written them in source code like func(param1,param2,param3), etc, as opposed to func(paramsArray). Now, this works because ExternalInterface::call expects the first param to be the name of function to be called and a variable (and optional) list of parameters. So, you just have to build an array that contains in its first position the function name and after that the rest of the args you want to pass. In this example, this is equivalent to this code: ExternalInterface.call(jsFunctionName,0,1,2,3,4,5); Cheers Juan Pablo Califano 2010/6/6 Ashim D'Silva <[email protected]> > The last 2 weeks were crazy and I completely lost track of this so I > apologise for not responding to the answers (cheers though!). We > couldn't find a solution so we used an array instead, but the idea was > this. > > I have: > > var objs:Array = [1, 2, 3, 4, 5]; // arbitrary length defined by the > number of parameters I receive from the XML. > > I want to pass it to javascript like this: > > ExternalInterface.call('jsFunc', objs[0], objs[1], objs[2], …); > > so that the JS can use whatever params are provided. > > I realise now however, that passing an Array (or name-value pairs) is > a far more stream-lined method of achieving this, but I'm still > curious if I could in fact build a function in a loop and then call it > after. Interpretive languages could possibly handle this real easily, > but is there an interesting workaround? > > Maybe something like: > > var st:String = "function() { jsFunc("; > for each(var i:String in objs) > { > st += i+", "; > } > st+=");"; > > ExternalInterface.call(st); > > It's reaching for stupidity because I lose the beautiful automatic > Array conversion that AS3 does, but curiosity has the better of me at > the moment. > > Cheers, > > Ashim > > The Random Lines > www.therandomlines.com > > > > > On 28 May 2010 22:13, Anthony Pace <[email protected]> wrote: > > > ............................................................................ > > If you want an array from javascript to actionscript > > > ............................................................................ > > somewhere in your class put something like: > > > > ExternalInterface.addCallback('SWFReceiver', as3Receiver); > > > > but remember that you need a receiver in as3: > > > > public function as3Receiver(a:Array /*or object, or *, etc...*/):void > { > > //do something with your array > > } > > > > then in js: > > > > var swfo = document.getElementById('idOfYourSwfElement'); > > swfo.SWFReceiver(yourArrayObject); > > > > > ................................................................................ > > if you want an array from AS3 to javascript > > > ................................................................................ > > > > var dataScript:XML= new XML("<![CDATA[ function(){ jsReceiver(["+ > > formattedArrayAsString +"]);} ]]>"); > > ExternalInterface.call(dataScript); > > > > > > > > On 5/26/2010 3:07 AM, Ashim D'Silva wrote: > >> > >> This seems fairly impossible but if there's an awesome way to do it > >> I'll be heaps grateful. > >> > >> I receive a function name and a set of parameters via XML > >> > >> <analytics> > >> <function> > >> <name>webtrends</name> > >> <params> > >> <param>98780</param> > >> <param>Joseph</param> > >> <param>Iceland</param> > >> </params> > >> </function> > >> </analytics> > >> > >> I'm hoping there's a way for me to fire an ExternalInterface.call() > >> function with any amount of parameters provided to me. > >> I'm one step away from telling the other side I'll send them an array, > >> but hoping for the long shot. > >> > >> Cheers, > >> > >> Ashim > >> > >> The Random Lines > >> www.therandomlines.com > >> _______________________________________________ > >> Flashcoders mailing list > >> [email protected] > >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > >> > >> > > > > _______________________________________________ > > Flashcoders mailing list > > [email protected] > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > > _______________________________________________ > Flashcoders mailing list > [email protected] > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ Flashcoders mailing list [email protected] http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

