Shortcut to Class Method fails in firefox, works in IE.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Arodicus
    New Member
    • May 2007
    • 12

    Shortcut to Class Method fails in firefox, works in IE.

    I have a static class method, MyObject.MySub. MyMethod(), which points to a handler in a Flash SWF (but I think that's inconsequential ). In reality, the path is a lot longer, so I'd like to make a simpler way for other programmers to access that method, such as this:

    var MyFunc = MyObject.MySub. MyMethod

    So they could just call MyFunc() instead. This "proxy" or "shorthand" works great in IE, but fails in Firefox/Safari and sometimes even crashes, saying it's an "illegal operation".

    Two questions:

    1) Is there a technical name for creating a simplified "pointer" to an existing function, so I can research this issue more easily, and.

    2) Anybody got a clue as to why Firefox and Safari Crash, but IE accepts this and works fine? Is there a better way to do this?


    Code sample follows:

    Javascript Code follows. Movie "TestMovie" is a SWF containing ExternalInterfa ce.addCallback( "TestFunction", this, TestFunction) ... what it does is not important. The failure is in calling it:


    Code:
    Code:
        function thisMovie(movieName) {
            if (navigator.appName.indexOf("Microsoft") != -1) {
                return window[movieName];
            }
            else {
                return document[movieName];
            }
        }
    
        var MyObject = new Object();
        MyObject.SWF = thisMovie("TestMovie");
    
        // This works in all browsers:
        MyObject.SWF.TestFunction();
        
        // Works in IE, but crashes in Firefox:
        var wtf = MyObject.SWF.TestFunction;
        wtf();
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    I can't see any reason why it fails in Firefox/Safari. I think the term you're looking for might be function objects. You might find this article useful.

    Comment

    • Arodicus
      New Member
      • May 2007
      • 12

      #3
      Originally posted by acoder
      I can't see any reason why it fails in Firefox/Safari. I think the term you're looking for might be function objects. You might find this article useful.
      Thanks. After extensive testing, the issue appears to be in the interface between the Flash plugin and Firefox; when performing a GetObjectByID on the object, it incorrectly interprets the DOM object as being a function, despite actually being an htmlEmbedElemen t. IE however, interprets the Flash Player as an a proper Object (because it sees the Object, not the Embed).

      I'm not sure who's to blame here... Adobe's interface or Mozilla for creating what's essentially a third classtype. Google shows less than 3500 entries for "htmlEmbedEleme nt", so my guess is that this is probably a scenario Adobe/Macromedia/Mozilla never thought of.

      The plugin, at the lowest level, only communicates with Javascript in JSON-like strings. Adobe injects quite a bit of hidden javascript into the page for conversion of Primitives ad Objects into a string, allowing more complex objects to "pass" across the barriers. they go across as strings, and are then reconstituted into their native Primitives, which is why functions and scoped objects cannot be passed. (Okay, passed EASILY).

      I suspect the pseudo-JSON converter gets confused when being handed a htmlEmbedElemen t as opposed to an Object, Function, or Primitive, and is sending the actual object, not a string, across to the plugin, causing the crash.

      Hopefully this defect will be addressed in a future release of the plugin, although it's so obscure that I'm nt holding my breath. In the meantime, I'm using a different method to get similar results.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        I'm not sure about this, but do the embed and object have the same name?

        Comment

        Working...