0

在下面的代码中,当我单击circle它的意思是更新使用的文本属性txttxt.Text = "gffdfgdsgsdgsdg";它不起作用?你知道怎么做吗?

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();
    }


}
4

2 回答 2

1

解决方案是使用小写文本属性;

txt.text = "更新文本";

于 2013-05-13T09:40:39.033 回答
1

更新“文本”属性后,您需要更新阶段(也许您的代码由于某种原因无法正常工作):

circle.onClick = function (event) {

    txt.text = "gffdfgdsgsdgsdg";

    stage.update();

};

PD:请注意,“text”属性是小写的。

于 2014-07-04T14:00:13.077 回答