469,573 Members | 1,642 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,573 developers. It's quick & easy.

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 ExternalInterface.addCallback("TestFunction",this, TestFunction) ... what it does is not important. The failure is in calling it:


Code:
Expand|Select|Wrap|Line Numbers
  1.     function thisMovie(movieName) {
  2.         if (navigator.appName.indexOf("Microsoft") != -1) {
  3.             return window[movieName];
  4.         }
  5.         else {
  6.             return document[movieName];
  7.         }
  8.     }
  9.  
  10.     var MyObject = new Object();
  11.     MyObject.SWF = thisMovie("TestMovie");
  12.  
  13.     // This works in all browsers:
  14.     MyObject.SWF.TestFunction();
  15.  
  16.     // Works in IE, but crashes in Firefox:
  17.     var wtf = MyObject.SWF.TestFunction;
  18.     wtf();
  19.  
Jan 24 '08 #1
3 1560
acoder
16,027 Expert Mod 8TB
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.
Jan 24 '08 #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.
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 htmlEmbedElement. 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 "htmlEmbedElement", 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 htmlEmbedElement 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.
Jan 30 '08 #3
acoder
16,027 Expert Mod 8TB
I'm not sure about this, but do the embed and object have the same name?
Jan 31 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Phil Green | last post: by
reply views Thread by Marcel | last post: by
7 posts views Thread by moondaddy | last post: by
reply views Thread by emin.shopper | last post: by
3 posts views Thread by KennethLundin | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.