Pjs undefined (processingjs)

if i use this:

$(document).ready(function() { pjs = Processing.getInstanceById("EyeCanvas"); console.log(pjs); } 

then pjs is always undefined

when i use this:

 function test() { pjs = Processing.getInstanceById("EyeCanvas"); console.log(pjs); } 

and trigger test () with the button, then pjs = D. Processing, as it should be.

I load the scripts in the following order:

  <script type="text/javascript" src="processing-1.3.6.min.js"></script> <script type="text/javascript" src="jquery1-7-1.js"></script> <script type="text/javascript" src="script.js"></script> 

How can I work with pjs without clicking the people button?

+4
source share
2 answers

Please try this - just to find out if this is a synchronization problem - pay attention to the replacement scripts:

 <script type="text/javascript" src="jquery1-7-1.js"></script> <script type="text/javascript" src="processing-1.3.6.min.js"></script> <script type="text/javascript" src="script.js"></script> var tId,pjs,cnt=0; $(document).ready(function() { tId=setInterval(function() { pjs = Processing.getInstanceById("EyeCanvas"); console.log(cnt+':'+pjs); if (pjs) clearInterval(tId); },500); }); 

and what does it say?

 var tId,pjs,cnt=0; $(document).ready(function() { pjs = Processing.getInstanceById("EyeCanvas"); console.log(cnt+':'+pjs); if (!pjs) tId=setInterval(function() { pjs = Processing.getInstanceById("EyeCanvas"); console.log(cnt+':'+pjs); if (pjs) clearInterval(tId); },500); }); 
+3
source

Yes mplungjan wrote the correct answer, but remember that when you use jQuery plugins you must first load the jQuery library all the time.

0
source

Source: https://habr.com/ru/post/1389916/


All Articles