AS2将多个动态文本字段更新为时间轴中的所有帧

时间:2013-01-30 04:09:02

标签: flash actionscript-2 flash-cs5

如何在4帧的时间轴中更新具有不同实例名称的多个动态文本字段?

我有一个名为(按钮)的movieclip使用同名的自定义类

1st Frame:
- Layer 1: Dynamic text named (txt1)
- Layer 2: Dynamic text named (txtbg1)

2nd Frame
- Layer 1: Dynamic text named (txt2)
- Layer 2: Dynamic text named (txtbg2)

4rd Frame
- Layer 1: Dynamic text named (txt4)
- Layer 2: Dynamic text named (txtbg4)

自定义类“按钮”代码:

class button extends MovieClip {
function button() { super(); }
function onLoad() {}
function setActivate(tf)
{
    delete this.onPress;
    delete this.onRelease;
    delete this.onRollOver;
    delete this.onRollOut;

    if (tf)
    {
        this.gotoAndStop(2);
        this.onRollOver = function()
        {
            this.gotoAndStop(3);
        }
        this.onRollOut = function ()
        {
            this.gotoAndStop(2);
        }
        this.onPress = function ()
        {
            this.gotoAndStop(4);
        }
        this.onRelease = function ()
        {
            if (_currentframe == 4)
            {
                //CLICKED DO ACTION
            }
            this.gotoAndStop(3);
        };
        return;
    }
    else
    {
        this.gotoAndStop(1);
    }
}
function setButtonText(txt)
{
    this["txt1"].text = txt;
    this["txtbg1"].text = txt;
    this["txt2"].text = txt;
    this["txtbg2"].text = txt;
    this["txt4"].text = txt;
    this["txtbg4"].text = txt;
}
}

在我的主场景中,我有一个名为“main”的动画片段使用相同名称的相同类。在那个moviecplip中有两个按钮说明之前

自定义类“主”代码:

    class main extends MovieClip
{
    var button1, button2;
    function main()
    {
        super();
    }
    function onLoad()
    {
        button1.setActivate(true);
        button2.setActivate(true);
        button1.setButtonText("OK");
        button2.setButtonText("CANCEL");
    }
}

谢谢并抱歉我的英语不好。

1 个答案:

答案 0 :(得分:1)

输入适当的帧时,唯一的方法是设置文本。原因是在帧中创建的文本字段总是会在每次输入帧时重新创建。所以决定为文本存储变量:

var txt:String; //for storing your text 
function setActivate(tf)
{
    delete this.onPress;
    delete this.onRelease;
    delete this.onRollOver;
    delete this.onRollOut;

    if (tf)
    {
        this.gotoAndStop(2);
        this.onRollOver = function()
        {
            this.gotoAndStop(3);
        }
        this.onRollOut = function ()
        {
            this.gotoAndStop(2);
            setButtonText(txt);
        }
        this.onPress = function ()
        {
            this.gotoAndStop(4);
            setButtonText(txt);
        }
        this.onRelease = function ()
        {
            if (_currentframe == 4)
            {
                //CLICKED DO ACTION
            }
            this.gotoAndStop(3);
        };
        return;
    }
    else
    {
        this.gotoAndStop(1);
        setButtonText(txt);
    }
}