Connecting Tech Pros Worldwide Help | Site Map

Flash 8 ExternalInterface and JavaScript Function.apply in Firefox

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 17th, 2007, 11:15 AM
Andrew Thelwell
Guest
 
Posts: n/a
Default Flash 8 ExternalInterface and JavaScript Function.apply in Firefox

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.


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.