[英]processing.js change script source
I need to find a way where I can dynamically change the source of a processing script inside an HTML document. 我需要找到一种方法,可以动态更改HTML文档中处理脚本的源。
This is the embedded script which works fine: 这是可以正常工作的嵌入式脚本:
<script type='application/processing' src='sketch.txt' id="applet">
</script>
Now I try to change the source: 现在,我尝试更改源:
$('#applet').attr('src', 'sketch2.txt');
alert($('#applet').attr('src'));
The alert shows that the source was changed to 'sketch2.txt' but the applet still remains the same. 警报显示源已更改为“ sketch2.txt”,但小程序仍然保持不变。 I think I need to refresh the script in some way. 我想我需要以某种方式刷新脚本。
Thank you in advance for any help! 预先感谢您的任何帮助!
I believe you have to manually attach each proc to the canvas, instead of just changing the the source file. 我相信您必须手动将每个proc附加到画布上,而不仅仅是更改源文件。 This worked here: 这在这里工作:
function first_call(processing) {
processing.size(300,300);
processing.background(100);
var called = false;
processing.draw = function() {
if (!called) { processing.println("called #1"); called = true; }
}
}
function second_call(processing) {
processing.size(400,400);
processing.background(200);
var called = false;
processing.draw = function() {
if (!called) { processing.println("called #2"); called = true; }
}
}
var canvas = document.getElementById('canvas1');
var processingInstance = new Processing(canvas, first_call);
var processingInstance = new Processing(canvas, second_call);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.