A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [RESOLVED] can a button or a radio button label be renamed?

  1. #1
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389

    resolved [RESOLVED] can a button or a radio button label be renamed?

    Hi,

    I haven't been able to rename my buttons programatically nor know how to rename a radio buttons label if possible
    Last edited by capdetrons; 12-29-2014 at 11:58 AM.

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


    OK, create a new AS2 fla and drag a component radiobutton into the library, then drag a component button into the library and use the code below.

    PHP Code:
    import mx.controls.RadioButtonGroup;
    import mx.controls.RadioButton;
    import mx.controls.Button;

    var 
    radioGroup:RadioButtonGroup;

    var 
    radioListener:Object = new Object();
    radioListener.click = function(e:Object)
    {
        
    trace(e.target.selection.data " : " e.target.selection._name);
    };

    for (
    1<= 10i++)
    {
        
    createClassObject(mx.controls.RadioButton,"RadioButton" i,i);
        
    this["RadioButton" i].label " Name: " i;
        
    this["RadioButton" i].groupName "radioGroup";
        
    this["RadioButton" i]._x 20;
        
    this["RadioButton" i]._y 20 + (20);
        
    this["RadioButton" i].data "Radio" i;
        
    this["RadioButton" 1].selected true;
        
    // *** optional styling
        
    this["RadioButton" i].setStyle("themeColor","0xFFFF00");
        
    this["RadioButton" i].setStyle("_xscale","100");
        
    this["RadioButton" i].setStyle("_yscale","100");
        
    this["RadioButton" i].setStyle("color","0xFF0000");
    }

    radioGroup.addEventListener('click',radioListener);

    for (
    1<= 10i++)
    {
        
    createClassObject(mx.controls.Button,"Button" i,10);
        
    this["Button" i].label "Capdetrons: " i;
        
    this["Button" i]._x 100;
        
    this["Button" i]._y 20 + (20);
        
    this["Button" i].data "Button" i;
        
    this["Button" i].onPress = function()
        {
            
    trace(this.data ": " this.label);
        };

    or you could do it more like so
    PHP Code:
    for (1<= 10i++)
    {
        var 
    newButton createClassObject(mx.controls.Button,"Button" i,10);
        
    newButton.label "Capdetrons: " i;
        
    newButton._x 100;
        
    newButton._y 20 + (20);
        
    newButton.data "Button" i;
        
    newButton.onPress = function()
        {
            
    trace(this.data ": " this.label);
        };



    now play around witht the code
    Last edited by fruitbeard; 12-29-2014 at 01:25 PM.

  3. #3
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    Hi,

    thanks, Fruit,

    solved that. I was placing my code inside the onPress function that's why it wouldn't work before.

    But, about button texts?

    Can those not be changed?

    I am trying:

    Code:
    if(language == "english"){
    	login_btn.loginBtn_txt.text = "Login";
    } else if(language == "catalan"){
    	login_btn.loginBtn_txt.text = "Accedir";
    }
    in the main timeline where the buttons is and I can't change it.

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi Cap,

    As far as I am aware you can not dynamically change the text inside of a button (you can with component buttons), you could however make your buttons into movieclips and have them act like buttons AND change your text inside.

    or have a dynaimc textfield above a your button and change the text of that, button would be graphic only

  5. #5
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    hadn't thought of the last option.

    thanks.

    Happy new year !!

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