2013-05-13 37 views
0

在下面的代碼中,當我點擊circle時,它的意思是使用txt.Text = "gffdfgdsgsdgsdg";來更新txt的文本屬性但是它不工作?你知道這是怎麼回事嗎?EaselJS使用onClick動態更新文本對象

function init() { 

    var canvas = document.getElementById('easel'); 
    var stage = new createjs.Stage(canvas); 

    var circle = new createjs.Shape(); 
    circle.graphics.beginFill("rgba(255,255,255,1)").drawCircle(40, 40, 40); 

    var shape = new createjs.Shape(); 
    shape.graphics.s('red').ss(10, 'round', 'round').mt(50, 50).lt(250, 250).lt(50, 250).cp(); 

    var shape2 = new createjs.Shape(); 
    shape2.graphics.s('blue').ss(20, 'round', 'round').mt(200, 50).lt(250, 250).lt(50, 250).cp(); 

    var txt = new createjs.Text("Hello CreateJS!", "15px Arial", "#FFF"); 
    txt.y = 45; 

    shape.onClick = function (event) { 
     this.x -= 1; 
    }; 
    shape2.onClick = function (event) { 
     this.x += 3; 
    }; 

    circle.onClick = function (event) { 

     alert('fhdfhdfhg'); 

     var s = this.x + ' y:' + this.y; 

     //txt.Text = "dfsdfs"; 

     txt.Text = "gffdfgdsgsdgsdg"; 

    }; 

    stage.addChild(shape); 
    stage.addChild(shape2); 
    stage.addChild(circle); 
    stage.addChild(txt); 

    //Update stage will render next frame 
    createjs.Ticker.setFPS(15); 
    createjs.Ticker.addEventListener("tick", handleTick); 

    function handleTick() { 

     console.log('test'); 

     circle.x += 2; 

     stage.update(); 
    } 


} 

回答

1

你需要更新後更新階段的「文本」屬性(也許你的股票不會出於某種原因):

circle.onClick = function (event) { 

    txt.text = "gffdfgdsgsdgsdg"; 

    stage.update(); 

}; 

PD:請注意,「文本」屬性是小寫。

1

的解決方案是使用下殼體文本屬性;

txt.text =「更新文本」;