Flash 8 ExternalInterface and JavaScript Function.apply in Firefox

A

Andrew Thelwell

Hi,

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
object.

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
idea)
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
"typeof()")
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

switch(args.length){
case(1):
myFlashMovie.doSomething(args[0]);
break;
case(2):
myFlashMovie.doSomething(args[0], args[1]);
break;
case(3):
myFlashMovie.doSomething(args[0], args[1], args[2]);
break;
}


....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!!


Andy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,734
Latest member
manin

Latest Threads

Top