0

How can I update multiple dynamic text fields with deferent instance name in a timeline with 4 frames ?

I have a movieclip named (button) using custom class with same name

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)

Custom class "button" code:

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

In my main Scene I have a movieclip named "main" using same class with same name. In that moviecplip there are included the two buttons say before

Custom class "main" code:

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

Thanks and sorry for my Bad English.

AkisC
  • 817
  • 2
  • 12
  • 27

1 Answers1

1

There is the only way to set texts when entering appropriate frame. The reason is that textfields created in frames always will be recreated on every enter their frames. So decision for you to store variable for text:

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);
    }
}
Serge Him
  • 936
  • 6
  • 8
  • Yes. This is that I wanted to avoid. Maybe to doublicate the "button" movieclip to a new one, with hardcoded the texts and change it on the fly when needed. Thanks for your interest! – AkisC Jan 30 '13 at 13:05
  • 1
    Or you can use field 'Variable' of textField in Flash CS (As on the [picture](http://gyazo.com/46d72b0a2100b8683c27b2adaad8d6f5)). So you dont need method setButtonText and just have to set txt variable in appropriate place. – Serge Him Jan 30 '13 at 13:20