A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: text button

  1. #1
    Member
    Join Date
    May 2002
    Location
    (SWEDEN
    Posts
    91

    text button

    can anyone explain how i go about doing this?:
    i have a box mc with a dynamic text on it. i also have this button. when i press the button i want the box mc to play and display a text in the text field. fairly easy, but the complicated part is that the next time i press the button i want a new text to appear, and then another and so on.
    i really need help with this,
    thanx in advance to the person who responds!

  2. #2
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Have your text as variables in the first frame.

    text1="bla bla"
    text2="more bla bla" etc and a........
    i=1;

    On your button...

    on(release){
    myMCwithTextfield.textField=eval("text"+i);
    i++
    }

    This will change the text everytime the button is clicked.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  3. #3
    Member
    Join Date
    May 2002
    Location
    (SWEDEN
    Posts
    91
    thanx, but can u give me the action script in a little more detail?

  4. #4
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Well, i rpresents a number. We set that number in the first frame .....i=1;
    We also specified some text variables text1 text2 etc

    On the button we have the code to display "text"+i which means
    text1

    The i++ makes the value of i to increase by one so the next time you click the button , "text"+i will mean text2 and so on.

    The target path myMCwithTextfield.textField suggests that you have a MC called myMCwithTextfield with a dynamic textfield called textField inside.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  5. #5
    Member
    Join Date
    May 2002
    Location
    (SWEDEN
    Posts
    91
    aaaaaaww!
    i just dont seem to get it! i dont really want to ask you this, but could u please make me a simple .fla? just so i get the hang of it, please.

  6. #6
    Member
    Join Date
    Dec 2001
    Location
    Netherlands
    Posts
    43
    put in a new array and use this as a source. (better a array than multiple variable, easier to update ;-))

    The only thing you need is a movieclip named 'button' and a dynamic textfield named 'Label' on layer1

    on layer 2 the code.

    here it is:

    button.onRelease = function () {
    var myArr = ["text1", "text2", "text3"];
    for (var item in myArr) {
    if (item < this.curItem || this.curItem == undefined) {
    this.newText = myArr[item];
    break;
    }
    }
    this.curItem = item
    this._parent["Label"].text = this.newText;
    };

  7. #7
    Member
    Join Date
    Dec 2001
    Location
    Netherlands
    Posts
    43

    the fla

    here is the fla
    Attached Files Attached Files

  8. #8
    Member
    Join Date
    May 2002
    Location
    (SWEDEN
    Posts
    91
    thanx a lot markus and piano!
    finaly i can carry on!

  9. #9
    Member
    Join Date
    May 2002
    Location
    (SWEDEN
    Posts
    91
    hi again.
    the thing works fine, just few things tough:
    i have like 22 different texts i want to display. but it displayes the first 10 inputs, then jumps to the two last ones. how can i make it go through all of them? and make it loop, begin at the start when all are done?

  10. #10
    Member
    Join Date
    Dec 2001
    Location
    Netherlands
    Posts
    43

    here it is

    //<skywalker@succesnet.nl>

    button.onRelease = function () {
    var myArr = ["text1", "text2", "text3","text4", "text5", "text6","text7", "text8", "text9", "text10", "text11", "text12"];
    for (var item = 0; item <= myArr.length - 1; item++)
    {
    trace(myArr.length)
    if(this.curItem == myArr.length){this.curItem = undefined}
    if (this.curItem < item || this.curItem == undefined)
    {
    this.newText = myArr[item];
    break;
    }
    }
    this.curItem = item;
    this._parent["Label"].text = this.newText;
    };

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center