PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Dynamic button labels
A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Dynamic button labels

  1. #1
    Junior Member
    Join Date
    Feb 2003
    Location
    Vancouver BC
    Posts
    29

    Dynamic button labels

    I'm using actionscript 2 in CS3. I posted yesterday in the newbie forum but got no response.

    I have a button in the library (exit_btn) and have dragged 3 instances to the stage (this is for the exit panel in a training program). Each button needs to do something different, so I want to put a different text label onto each. How can I do that? I've exhausted every approach I can think of.

    Each of the 3 buttons on stage is a different instance name. The buttons have a dynamic text field called 'dt', but 'button1.text =' or 'button1.dt.text=' doesn't change anything. The only way I can make this work is to create a variable also called 'dt', but then all three buttons hold the same text label.

    How can I do this? Must I change these to movie clips for this (I'd rather not).

    TIA Ron

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    post your fla

  3. #3
    Junior Member
    Join Date
    Feb 2003
    Location
    Vancouver BC
    Posts
    29

    Dynamic button labels - file attached

    Hello fruitbeard - hmmm...the file is too big to send to the list, even after deleting a number of library items, and zipping it, not sure why. For now I'll paste the code below that I'm trying to assign english/french or spanish text to the two buttons on a form.

    Ron

    Note: The button name instances are exit_exit_btn and exit_exit_btn1


    Language = 'en';

    if (Language == 'en'){
    exit_dt.text = "What would you like to do?";
    //STUCK HERE - HOW TO ASSIGN DIFFERENT LABELS TO EACH BUTTON?
    //exit_exit_btn.dt.setText = "zzzzzzzzzzzz";

    //exit_exit_btn.exit_dtext = "Quit This Program 77";
    exit_exit_btn.exit_dtext = "Quit This Program";

    exit_exit_btn2.exit_dtext = "Quit This";


    //exit_exit_btn.text= "Quit This Program";
    } else if (Language == 'fr') {
    exit_dt.text = "Que voudriez-vous faire ?";
    exit_dtext = "Stoppez ce Program";
    exit_dtext1 = "Stoppez ce Program";
    } else if (Language == 'sp') {
    exit_dt.text = "¿Qué usted querría hacer?";
    exit_dtext = "Pare este programa";
    exit_dtext1 = "Pare este programa";
    }

    //_level0.engine.trackingData.Language

  4. #4
    Junior Member
    Join Date
    Feb 2003
    Location
    Vancouver BC
    Posts
    29
    I haven't done a very good job of explaning this! exit_dtext is the dynamic text field, and also I have a var called exit_dtext. This works in assigning label names - but it assigns the same name to both buttons, which is no good. I need to assign label text to each individual button (need a third button later too).

    Ron

  5. #5
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Dynamic textbox inside the movieclip named dt
    Don't use variable name, use instance name.

    in the first frame of the main timeline:

    Actionscript Code:
    myMovieClip1.dt.text="What ever you want here";

    myMovieClip2.dt.text="What ever you want here";

    myMovieClip3.dt.text="What ever you want here";

    Hope this helps

  6. #6
    Junior Member
    Join Date
    Feb 2003
    Location
    Vancouver BC
    Posts
    29

    Unhappy Dynamic Button Text

    Hello AngelHDZ - thanks, I have tried that, doesn't work....but I am using a 'button' symbol type, not a movieclip, you specified a movieclip. Do I have to convert to a movieclip? Is there no way to do this with buttons?
    Thanks
    Ron

  7. #7
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    There is no easy way to access dynamic textFields inside of buttons, why put it there you ask, I know not.

    but with the use of movieClips you can emulate buttons.

    here is some example code:

    Actionscript Code:
    Language = 'en';

    if (Language == 'en')
    {
        button1.buttonText.text = "Quit This Program 77";
        button2.buttonText.text = "Quit This Program";
        button3.buttonText.text = "Quit This";
    }
    else if (Language == 'fr')
    {
        button1.buttonText.text = "Que voudriez-vous faire ?";
        button2.buttonText.text = "Stoppez ce Program";
        button3.buttonText.text = "Stoppez ce";
    }
    else if (Language == 'sp')
    {
        button1.buttonText.text = "¿Qué usted querría hacer?";
        button2.buttonText.text = "Pare este programa";
        button3.buttonText.text = "Pare este";
    }
    // button 1 - actually is movieclip
    button1.onRollOver = function()
    {
        this.gotoAndStop(2);
    };
    button1.onRollOut = button1.onDragOut = function ()
    {
        this.gotoAndStop(1);
    };
    button1.onPress = function()
    {
        this.gotoAndStop(3);
        // Have whatever command you need here
    };
    button1.onRelease = button1.onReleaseOutside = function ()
    {
        this.gotoAndStop(1);
        // Have whatever command you need here
    };
    // button 2 - actually is movieclip
    button2.onRollOver = function()
    {
        this.gotoAndStop(2);
    };
    button2.onRollOut = button2.onDragOut = function ()
    {
        this.gotoAndStop(1);
    };
    button2.onPress = function()
    {
        this.gotoAndStop(3);
        // Have whatever command you need here
    };
    button2.onRelease = button2.onReleaseOutside = function ()
    {
        this.gotoAndStop(1);
        // Have whatever command you need here
    };

    Failing that you could just put some (unselectable)text over the buttons, or use static text(cough)

    with the movieclip as button , just make a movie clip, with 3 frames all with a stop(); command on them, make each of the 3 frames button like, add a layer with your text on, (named buttonText on my example) then go from there.
    Last edited by fruitbeard; 07-18-2012 at 02:59 PM.

  8. #8
    Junior Member
    Join Date
    Feb 2003
    Location
    Vancouver BC
    Posts
    29

    Dynamic Button Labels

    Hello Fruitbeard:

    Thanks for those suggestions, I have created buttons and basically followed your instructions and it's close. One problem, that I'm a bit mystified by...the dynamic text is lost going from frame to frame. The button text appears properly on entry, but when I do a rollover it is lost. I would have thought the dynamic text would maintain between the frames but obviously not...have I done something wrong here, or do I need to reload the text every time there is a rollover, rollout, etc?

    Thanks



    Language = 'en';


    if (Language == 'en'){
    exit_dt.text = "What would you like to do?";

    exit_mc1.dt.text="Quit this Program";
    exit_mc2.dt.text="Return to the Learning Center";
    exit_mc3.dt.text="Cancel";

    } else if (Language == 'fr') {
    exit_dt.text = "Que voudriez-vous faire ?";

    exit_mc1.dt.text = "Stoppez ce Program";
    exit_mc2.dt.text="zzzzzzzzzzzzzzzzz";
    exit_mc3.dt.text="Cancel";

    } else if (Language == 'sp') {
    exit_dt.text = "¿Qué usted querría hacer?";

    exit_mc1.dt.text = "Pare este programa";
    exit_mc2.dt.text="vvvvvvvvvvvvvvvvvvv";
    exit_mc3.dt.text="Cancel";
    }

    //_level0.engine.trackingData.Language


    exit_mc1.onRollOver = function() {
    this.gotoAndStop(2);
    };
    exit_mc1.onRollOut = function() {
    this.gotoAndStop(1);
    };
    exit_mc1.onPress = function() {
    this.gotoAndStop(3);
    debug("PUSHED BUTTON - ACTION NEEDED!!!!");
    };

    exit_mc1.onRelease = function() {
    this.gotoAndStop(1);
    };

  9. #9
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    basically put another layer above the three frames on the movieclip which extends across all three frames.
    remove it from the first frame

  10. #10
    Junior Member
    Join Date
    Feb 2003
    Location
    Vancouver BC
    Posts
    29

    Dynamic button labels

    I see...OK I'll try that. Thanks Fruitbeard, you have been very helpful! It's been a slow process of trying to get my old head to think like AS.

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