By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,247 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,247 IT Pros & Developers. It's quick & easy.

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

P: 12
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
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
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

P: 12
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
Expert Mod 15k+
P: 16,027
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.