-
[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.
-
.
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 (i = 1; i <= 10; i++)
{
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 + (i * 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 (i = 1; i <= 10; i++)
{
createClassObject(mx.controls.Button,"Button" + i,i + 10);
this["Button" + i].label = "Capdetrons: " + i;
this["Button" + i]._x = 100;
this["Button" + i]._y = 20 + (i * 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 (i = 1; i <= 10; i++)
{
var newButton = createClassObject(mx.controls.Button,"Button" + i,i + 10);
newButton.label = "Capdetrons: " + i;
newButton._x = 100;
newButton._y = 20 + (i * 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.
-
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.
-
.
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
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|