Search code examples
javascriptflashinheritancegoogle-earth-plugin

Javascript Extend NPObject (Google Earth Plugin API)


I'm trying to extend KmlPlacemark in the Google Earth API. Google uses factory methods to create the objects so I can't do something like this:

    KmlPlacemark.prototype.foo = function () { /* ... */ }

I tried to simply add methods to each of the objects after they were created

    function foo () { /* ... */ }
    placemarkObj.foo = foo;

but it throws

Error: Trying to add unsupported property on NPObject!

I ended up just making a wrapper for it, but I'd still want to know if there's any other way of doing it.


Solution

  • I'm not absolutely sure, but it looks like you're trying to extend objects that exist inside the browser plugin, which isn't possible - although these objects can be accessed in JavaScript, their implementation is in native code inside the NPAPI plugin.