Problems accessing M4J editor

User 873a9ae9d0

03-02-2014 19:13:41

HI,


In my asp.net app I have a form with an iframe that is a container for M4J.


By certain reasons I do not want in my Javascript code use getMarvinPromise to access the editor.

The main reason is that getMarvinPromise is using an async pattern that is giving me problems.

Now I tried to access the editor as outlined in the 'Marvin for Javascript - How to embed it' doc.

This is my code:


var marvinSketcherInstance;



var s="Themolfile";


 


var eframeWin = document.getElementById("MyIframeID").contentWindow;

var marvin = eframeWin.marvin;

 marvin.onReady(function () {
 
 if (typeof marvin.Sketch != 'undefined') {
 
  marvinSketcherInstance = marvin.Sketch;
  marvinSketcherInstance.importAsMol(s);
 
  ....


marvinSketcherInstance seems to be defined, but the call to ImportAsMol(s) does nothing. I tried other methods such as isEmpty too. Same result.


What am I doing wrong ???


BTW: There seems to be a documentation error in the mentioned document. In the doc marvin.sketch is used. I assume it should mean marvin.Sketch.


 


Hope one can help . Any help is highly appreciated.


regards


Hans-Juergen


AKos GmbH


 

ChemAxon 7c2d26e5cf

04-02-2014 18:29:18

You use wrong reference in your code:


marvin.Sketch = the "class" that implements the sketcher in the marvin package. It has only "static" functions.


marvin.sketcherInstance = the current instance of the marvin.Sketch class in the editor.html.


The imporAsMol function belongs to the instance (not the class). That's why you got a NoSuchMethod error.


If I were you, I would modify your code by the following way:


marvin.onReady(function () {
   if (typeof marvin.sketcherInstance != 'undefined') {
     marvinSketcherInstance = marvin.sketcherInstance;
   marvinSketcherInstance.importAsMol(s);
 }
});