0

I am playing with a very simple little shooter to learn about easeljs, tweenjs, and canvas coding. I've run into a problem that's stumped me.

I get an unexpected end of input error in Chrome and it indicates line 1. Whats up with that?

Note that in the code below I have commented out all of the keyboard input code. The error no longer appears. When I uncomment either the document.addEventListener or window.addEventListener input code the error is thrown again. And further experimentation led me to believe it has to do with the event object but beyond that I have no idea.

Hope someone can help!

window.addEventListener('load', eventWindowLoaded, false);

function eventWindowLoaded() {
    init();
}

function init() {
    console.log("init hit");
    canvas = document.getElementById("canvas");
    stage = new Stage(canvas);

    createStarField();

    shipImg = new Image();
    shipImg.onload = onShipLoaded;
    shipImg.src = "ship1.png";

    Ticker.setFPS(30);

    Ticker.addListener(window);

 /*   document.addEventListener('keydown', function(event) {
        switch(event.keyCode)  {
            case 37: // left
                moveLeft = true; moveRight = false;
                break;

            case 38: moveUp = true; moveLeft = false;
                break;

            case 39: moveRight = true; moveLeft = false;
                break;

            case 40: moveDown = true; moveUp = false;
                break;
        }
    }, false);

    document.addEventListener('keyup', function() {
        switch(e.keyCode) {
            // left
            case 37: moveLeft = false;
                break;
            // up
            case 38: moveUp = false;
                break;
            // right
            case 39: moveRight = false;
                break;
            // down
            case 40: moveDown = false;
                break;
    }
}, false);
*/

/*function onKeyDown(e) {
    //if(!e) { var e = window.event; }

    switch(e.keyCode) {
        // left
            case 37: moveLeft = true; moveRight = false;
            break;

            case 38: moveUp = true; moveLeft = false;
            break;

            case 39: moveRight = true; moveLeft = false;
            break;

            case 40: moveDown = true; moveUp = false;
            break;
    }
}

function onKeyUp(e) {
   // if(!e) { var e = window.event; }
    switch(e.keyCode) {
        // left
        case 37: moveLeft = false;
            break;
        // up
        case 38: moveUp = false;
            break;
        // right
        case 39: moveRight = false;
            break;
        // down
        case 40: moveDown = false;
            break;
    }
*/
    function checkMovement() {
        if(moveLeft)
        {
            ship.x -= speed;
            if(ship.x < 0)
                ship.x = 640;
        }
        else if(moveRight)
        {
            ship.x += speed;
            if(ship.x > 640)
                ship.x = 0;
        }

        if(moveUp)
        {
            if(ship.y - speed > 24)
                ship.y -= speed;
        }
        else if(moveDown)
        {
            if(ship.y + speed < 460)
                ship.y += speed;
        }
    }

    function onShipLoaded() {
    ship = new Bitmap(shipImg);
    ship.regX = ship.image.width * .05;
    ship.regY = ship.image.height * 0.5;
    ship.x = 320;
    ship.y = 450;

    stage.addChild(ship);
}

function createStarField() {
    console.log("create star field");
    stars = new Array();

    g = new Graphics();
    g.setStrokeStyle(1);
    g.beginStroke(Graphics.getRGB(255,255,255));
    g.beginFill(Graphics.getRGB(255,255,255));
    g.drawCircle(0,0,1);

    for(var i = 0; i < 100; ++i) {
        var s = new Shape(g);
        stars.push(s);
        s.x = randRange(10,630);
        s.y = randRange(-250, 470);
        s.scaleX = randRange(0.5, 2);
        s.scaleY = s.scaleX;
        s.alpha = Math.random() + 0.2;

        stage.addChild(s);
    }
}

function randRange(min, max) {
    return Math.floor(Math.random()*(max - min)) + min;
}

function tick() {
    console.log("tick hit");
    updateStarField();
    checkMovement();
    stage.update();
}

function updateStarField() {
    console.log("updateStarField()");
    var curStar;
    var limit = stars.length;
    for(var i = 0; i < limit; ++i) {
        curStar = stars[i];
        curStar.y += 4
            if(curStar.y > 480) {
                curStar.x = randRange(10,630);
                curStar.y = -randRange(20, 450);
            }
    }
}
3
  • Where's the closing curly brace of init? It seems that it's missing. Commented Mar 16, 2012 at 23:01
  • 1
    code.google.com/p/chromium/issues/detail?id=11037 Commented Mar 16, 2012 at 23:10
  • Thank you!! My issue is almost exactly identical - instead of referencing a line number past the end of the file it references line 1 whether it be blank, a comment, etc. Commented Mar 16, 2012 at 23:33

1 Answer 1

1

The last commented out onKeyUp(e) function lacks a closing curly brace (})

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you - the error however remains the same even upon correcting that.
Is your file cached? hit ctrl-R to make sure it is grabbing the latest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.