Re: [Flashcoders] External Interface with looped parameters

2010-06-06 Thread Ashim D'Silva
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 anthony.p...@utoronto.ca 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
                namewebtrends/name
                params
                        param98780/param
                        paramJoseph/param
                        paramIceland/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
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] External Interface with looped parameters

2010-06-06 Thread Anthony Pace
What you are suggesting, is almost the same as I suggested, except that 
you are avoiding the xml object and instead using a string; however, 
because of how a string is converted when passing the data, I wouldn't 
recommend it for anything too complex.


On 6/6/2010 7:13 AM, Ashim D'Silva wrote:

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 Paceanthony.p...@utoronto.ca  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
namewebtrends/name
params
param98780/param
paramJoseph/param
paramIceland/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
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


   

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

   


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] External Interface with looped parameters

2010-06-06 Thread Juan Pablo Califano
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 as...@therandomlines.com

 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 anthony.p...@utoronto.ca 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
 namewebtrends/name
 params
 param98780/param
 paramJoseph/param
 paramIceland/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
  Flashcoders@chattyfig.figleaf.com
  http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 
 
 
  ___
  Flashcoders mailing list
  Flashcoders@chattyfig.figleaf.com
  http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] External Interface with looped parameters

2010-05-28 Thread Anthony Pace


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
namewebtrends/name
params
param98780/param
paramJoseph/param
paramIceland/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
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

   


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


[Flashcoders] External Interface with looped parameters

2010-05-26 Thread Ashim D'Silva
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
namewebtrends/name
params
param98780/param
paramJoseph/param
paramIceland/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
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] External Interface with looped parameters

2010-05-26 Thread kennethkawam...@gmail.com
You can pass any number of parameters with ExternalInterface.call()
method - or are you talking about something else...?
-- 
Kenneth Kawamoto
http://www.materiaprima.co.uk/

On 26 May 2010 08:07, Ashim D'Silva as...@therandomlines.com 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
                namewebtrends/name
                params
                        param98780/param
                        paramJoseph/param
                        paramIceland/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
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] External Interface with looped parameters

2010-05-26 Thread Glen Pike

On 26/05/2010 09:33, kennethkawam...@gmail.com wrote:

You can pass any number of parameters with ExternalInterface.call()
method - or are you talking about something else...?
   

I think he means a variable number of parameters.

Can you pass an object like an array?
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] External Interface with looped parameters

2010-05-26 Thread kennethkawam...@gmail.com
You can count them in the receiving function, e.g. arguments.length in
JavaScript. (Then may be I misunderstood again ;)

-- 
Kenneth Kawamoto
http://www.materiaprima.co.uk/

On 26 May 2010 09:39, Glen Pike g...@engineeredarts.co.uk wrote:
 On 26/05/2010 09:33, kennethkawam...@gmail.com wrote:

 You can pass any number of parameters with ExternalInterface.call()
 method - or are you talking about something else...?


 I think he means a variable number of parameters.

 Can you pass an object like an array?
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders