如何在影片剪辑[AS3]中动态创建文本?

时间:2016-10-22 11:53:50

标签: actionscript-3 flash

我想点击按钮而非文字

btn_start.t1.text = "hello world" // not working

1 个答案:

答案 0 :(得分:0)

粗糙的代码......你将不得不继续努力但似乎很容易。 您只需在创建每个状态时为SimpleButton的每个状态设置文本。 这就是全部。 现在您可以嵌入字体,更改TextField的样式......

var btn_start:SimpleButton = new SimpleButton();
addChild(btn_start);
btn_start.upState = drawUpstate(0xcc5500,"upstate");
btn_start.downState = drawDownstate(0x444444,"downstate");
btn_start.hitTestState = drawDownHitTeststate();
btn_start.overState = drawOverState(0x888888,"overtstate");
addChild(btn_start);
placeButton(btn_start,50,50);
function drawUpstate(color:int, btnLabel:String):Sprite {
    var btn_color:uint = color;
    var mc:Sprite = new Sprite();
    var textLabel:Sprite = new Sprite();
    var tf : TextField = new TextField();
    tf.textColor = 0xffffff;
    tf.text = btnLabel;
    mc.addChild(tf);
    var g:Graphics = mc.graphics;
    drawButton(g,btn_color);
    return mc;
}
function drawDownstate(color:int, btnLabel:String):Sprite {
    var btn_color:uint = color;
    var mc:Sprite = new Sprite();
    var textLabel:Sprite = new Sprite();
    var tf : TextField = new TextField();
    tf.textColor = 0xffffff;
    tf.text = btnLabel;
    mc.addChild(tf);
    var g:Graphics = mc.graphics;
    drawButton(g,btn_color);
    return mc;
};
function drawDownHitTeststate():Sprite {
    var btn_color:uint = 0x0000000;
    var mc:Sprite = new Sprite();
    var g:Graphics = mc.graphics;
    drawButton(g,btn_color);
    return mc;
};
function drawOverState(color:int, btnLabel:String):Sprite {
    var btn_color:uint = color;
    var mc:Sprite = new Sprite();
    var textLabel:Sprite = new Sprite();
    var tf : TextField = new TextField();
    tf.textColor = 0xffffff;
    tf.text = btnLabel;
    mc.addChild(tf);
    var g:Graphics = mc.graphics;
    drawButton(g,btn_color);
    return mc;
};
function drawButton(g:Graphics,color:uint) {
    g.beginFill(color,1);
    g.drawRect(0,0,100,20);
    g.endFill();
};
function placeButton(btn:SimpleButton,x:uint,y:uint):void {
    btn.x = x;
    btn.y = y;
};

最好的问候。

尼古拉斯