小编kuk*_*c67的帖子

Javascript错误:未捕获的ReferenceError:[function]未定义

我有两个js文件,都由一个HTML文件调用.

<script type="text/javascript" src="scripts/levelmovement.js"></script>
<script type="text/javascript" src="scripts/generation.js"></script>
Run Code Online (Sandbox Code Playgroud)

levelmovement.js的一部分:

function moveLevel(){
    if(firstreset == true){
        resetTime();
    }
    var time2 = new Date();
    var millis2 = time2.getTime();
    var millis3 = millis2 - millis1;
    poschange = Math.floor(millis3 / 5);
    for(i = 0; i < chunkpos.length; i++){
        temppos[i] = chunkpos[i] - poschange;
        if(temppos[i] <= -150){
            temppos[i] += 1200;
            generate(i);
        }
        pos = temppos[i];
        document.getElementById('chunk' + i).setAttribute('style','left: ' + pos + 'px;');
    }
}
Run Code Online (Sandbox Code Playgroud)

函数"moveLevel()"的调用方式如下:

window.onload = function(){
    gameLoop();
}

function gameLoop(){
    if(currentscreen == 'playing'){
        moveLevel(); …
Run Code Online (Sandbox Code Playgroud)

javascript

1
推荐指数
1
解决办法
2万
查看次数

是否为线程更新了公共静态变量?(它是线程安全的吗?)

我尝试了以下内容,但没有奏效:

"开始"课程:

public class Start implements Runnable {

    Start start;
    LoadExample loadExample;
    Thread mainThread;
    Thread loadExampleThread;

    private boolean running = false;
    public static boolean isExampleLoaded = false;

    public static void main(String[] args) {
        begin = new Start();
        loadExample = new LoadExample();
        begin.start();
    }

    public synchronized void start() {
        mainThread = new Thread(this, "Main");
        mainThread.start();
        loadExampleThread = new Thread(loadExample, "Load Example");
        loadExampleThread.start();
    }

    public void run() {
        running = true;
        while (running) {
            if(isExampleLoaded){
                System.out.println("Loaded!");
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

"LoadExample"类:

public …
Run Code Online (Sandbox Code Playgroud)

java thread-safety

1
推荐指数
1
解决办法
157
查看次数

标签 统计

java ×1

javascript ×1

thread-safety ×1