0

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

我有一个名为(按钮)的影片剪辑,使用同名的自定义类

第一帧:
- 第 1 层:名为 (txt1) 的动态文本
- 第 2 层:名为 (txtbg1) 的动态文本

第二帧
- 第 1 层:名为 (txt2) 的动态文本
- 第 2 层:动态文本命名 (txtbg2)

第 4 帧
- 第 1 层:动态文本命名 (txt4)
- 第 2 层:动态文本命名 (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");
    }
}

感谢和抱歉我的英语不好。

4

1 回答 1

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);
    }
}
于 2013-01-30T06:39:25.843 回答