Flash 8 ExternalInterface and JavaScript Function.apply in Firefox

Discussion in 'Javascript' started by Andrew Thelwell, May 17, 2007.

  1. 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.
    Andrew Thelwell, May 17, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Siegl
    Replies:
    1
    Views:
    952
    Marrow
    Jul 18, 2003
  2. Peter Motzfeldt
    Replies:
    1
    Views:
    151
  3. Peter Nicolai Motzfeldt

    Win32Ole, ExternalInterface (Flex), return objects

    Peter Nicolai Motzfeldt, Mar 21, 2007, in forum: Ruby
    Replies:
    0
    Views:
    85
    Peter Nicolai Motzfeldt
    Mar 21, 2007
  4. Cliff R.
    Replies:
    6
    Views:
    144
  5. HopfZ

    Function.call and Function.apply

    HopfZ, Aug 25, 2006, in forum: Javascript
    Replies:
    1
    Views:
    89
    Lasse Reichstein Nielsen
    Aug 25, 2006
Loading...

Share This Page