Problem with setAtomExtraLabel

User 694b0b0519

17-05-2005 14:12:29

I can't find how to use this MView function with my applets.


I think i have a problem with the call of those functions as noone of them seems to want to work. The applet just don t show when i'm calling them, here is a sample of the code, i've tried many different things and read the tutorial many times, so i must miss something stupid and easy, anyway here it is :





<SCRIPT LANGUAGE="JavaScript1.1" SRC="/marvin/marvin.js"></SCRIPT>


<SCRIPT LANGUAGE="JavaScript1.1">


<%int k=0;%>


<!--


function f(cel,at1,at2,at3,sym1,sym2,sym3) {


document.MView1.setAtomExtraLabel(cel,at1,sym1);


document.MView1.setAtomExtraLabel(cel,at2,sym2);


document.MView1.setAtomExtraLabel(cel,at3,sym3);


}


var k=0;


mview_name = "MView1";


mview_begin("/marvin", 1250, 280*<%=nbrow%>);


mview_param("background", "#efefef");


mview_param("molbg", "#efefef");


mview_param("rows", "<%=nbrow%>");


mview_param("cols", "5");


mview_param("border", "1");


mview_param("atomNumbersVisible",true);


mview_param("layout", ":2:1:M:1:0:1:1:s:n:L:0:0:1:1:c:n:0:10");


mview_param("param", ":M:250:250:L:12b");








<% for (int j = 0; j<obj.length; j++) {


String adress = (String)obj[j];


String[] add = adress.split(" ");


String msS = (String)totAdress.get(adress);


%>


mview_param("cell<%=k%>", "|<%=msS%>"+"|Atom <%=add[0]%> : Ar Atom <%=add[1]%> : Ar Atom <%=add[1]%> : Ar");


mview_param("selection<%=k%>","<%=add[0]%>,<%=add[1]%>,<%=add[2]%>");


f(k,<%=new Integer(add[0])%>,<%=new Integer(add[1])%>,<%=new Integer(add[2])%>,"Ar","Ap","Hp");


<%k++;%>


<%}%>


mview_end();


//-->


</SCRIPT>


</CENTER>








It works perfectly when i don't call the F method.


What do you think ?

ChemAxon 7c2d26e5cf

23-05-2005 17:21:38

You called your function too early. Before you call a method of MView, you have to wait until applet is started.


It means that you have to wait the finishing of molecule loading.


By the following trick, you can delay the calling of your function untill all molecules are loaded.


Code:



var sum = 0;


var n = 6;  // cell number


function molloaded(i) {


   sum = sum + i + 1;


   x = n * (n + 1) / 2;


   if(sum >= x) {   // all molecule are loaded-in


       // insert your code


   }


}





mview_mayscript = true;


mview_begin(...);


mview_param("rows", ...);


mview_param("cols", ...);


...


mview_param("cell0", ...);


mview_param("cell1", ...);


...


mview_param("cell5",...);


mview_param("molChanged0","js:molloaded(1)");


mview_param("molChanged1","js:molloaded(2)");


...


mview_param("molChanged5","js:molloaded(6)");


mview_end();





The JavaScript code that is specified in the molChanged0 applet parameter is evaluated when the viewer loaded-in the molecule.


http://www.chemaxon.com/marvin/doc/dev/viewman.html#molChanged0