Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language

Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Javascript / Client Side Development

Flash 8 ExternalInterface and JavaScript Function.apply in Firefox


I am having problems in Firefox with calling a Flash function from
JavaScript using Flash 8's ExternalInterface.

Basically, I can call the function just fine using the straight-
forward method:

  myFlashMovie.doSomething(param1, param2, param3);

...that works fine.

However, the functionality I am creating is slightly more complex and
therefore calls for the use of the "apply" method of the Function

What I therefore want to do is essentially this:

  var args = new Array(param1, param2, param3); //build my array of
params (in the real code, it's not so simple as this, but you get the
  var func = myFlashMovie.doSomething; // set variable func to
reference my flash function

  func.apply(this, args);

This then allows me to call different flash functions dynamically,
with different numbers of params etc. As I've said, the actual setup
is slightly different so no need to discuss whether or not this kind
of approach is necessary or not (it is).

The problem is, that using the Function.apply methood DOES NOT work in
Firefox for executing Flash functions. I have tested various things,
as follows:

 1) Does Function.apply work in Firefox for executing normal JS
functions -- YES
 2) Does the JavaScript inside Firefox recognise
"myFlashMovie.doSomething" as being a function -- YES (tested using
 3) Can myFlashMovie.doSomething be executed using the normal method
of myFlashMovie.doSomething(p1, p2, p3) etc. -- YES, it works fine!

So, my only solution currently is very inelegant indeed, and that is
to do something like this

      myFlashMovie.doSomething(args[0], args[1]);
      myFlashMovie.doSomething(args[0], args[1], args[2]);

...which works, yes, but isn't exactly great.

So, I was wondering if anyone had managed to execute a Flash function
from JS, in Firefox, and successfully done it using Function.apply.
Alternatively, anyone got better alternative to my switch(args.length)
method? Maybe one that's a bit less limiting?

Many thanks in advance!!


Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc