PDA

View Full Version : Change the name of a simple button?


MarionC
03-03-2008, 11:37 AM
Hello all,

I don't mean what the button would be referenced by within the program but rather as it appears to the user. I am using common library buttons but I have no clue how to change their names on the buttons from "Enter" to something else.

I've looked everywhere, from Adobe's reference pages, to all my books + google. :x

Any help or hints are appreciated.
-m

Mazoonist
03-03-2008, 12:50 PM
Do you mean the Button component? From the components panel?

If so, you need to change the "label" property to make the button's face read something else. By default, they say "Label" (not "Enter" as you indicated). To change the label property manually, use the component inspector. With the Button on the stage selected, go to the component inspector panel and change the "label" entry to whatever you want the Button to say. If "Enable Live Preview" is on (it's on the Control menu), you'll immediately see the new label on the button's face.

To change the label property with Actionscript, give the Button on stage an instance name, then in your actionscript, do this:
myButton.label = "Submit";
In this case, you won't see the change until the program runs, of course.

MarionC
03-03-2008, 06:28 PM
Hi Mazoonist,

I tried using myButton.label (in this case I call it startButton.label) and tried to set it to a name of my choice but it doesn't seem to matter. The name of the button is still "Enter."

I tried going to the Components Inspector and found the "label" field and created buttons that way too and naming them that way worked nicely but it had no effect on the buttons I made earlier.

I named the instance of my button via the Property -> Properties where I name my button as an instance of "circle bubble green" (a common library button premade class I copied into my library to use)

I'm confused here atm. Then I thought I'd have to create the button dynamically to access it rightly but there is no change in the button name when do that and run the .fla file.

Is there no way to change the name of a predefined button given in the common library buttons section? (to me that seems odd.)

Thanks for you help, btw, Mazoonist.

-m

MarionC
03-03-2008, 08:17 PM
Hello!

Ok, I was messing with this a bit and it seems that the "Enter" is a text field within the button itself. Also, I have 3 different buttons defined but changing this item from "Enter" to "Start" changes all three of them! Lol.

I've tried to name them using the .label assignment statement, however this has no effect on it. To work around this, I've created textfields and am looking for a way to attach the correct name to each respective button.

I don't know if I'm going about this the right way. It seems creating your own button is better to do than to use the common library buttons.

-m

MarionC
03-04-2008, 05:29 AM
Hello again!

I figured out how to change the name of the button and that was by changing the timeline of the button itself and changing the textField label that was defined to that button. Phew. It sure isn't intuitive for a newbie how to do this simple task.

Thank you Mazoonist for your support. I learn something new everyday (re: .label assignment command.)

-m

lordofduct
03-04-2008, 05:42 AM
Hello again!

I figured out how to change the name of the button and that was by changing the timeline of the button itself and changing the textField label that was defined to that button. Phew. It sure isn't intuitive for a newbie how to do this simple task.

Thank you Mazoonist for your support. I learn something new everyday (re: .label assignment command.)

-m
Where did you create this button? It sounds a bit convoluted (complex) for what it is needed for.

If you just add the base button component to your library, import fl.controls.button and then create an instance of said button in your code you can just alter myButton.label = "what ever"

You can even alter the text font and the sort... like this:
changes font to "Georgia"

myButton.setStyle("textFormat", new TextFormat("Georgia"));


here's the example from Adobe's reference sheet:

package
{
import fl.controls.Button;
import fl.controls.TextArea;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextFormat;

public class ButtonExample extends Sprite
{
private var b1:Button;
private var b2:Button;
private var b3:Button;
private var ta:TextArea;

public function ButtonExample() {
createTraceField();
setupButtons();
}
private function createTraceField():void {
ta = new TextArea();
ta.setSize(200, 300);
ta.move(200, 10);
addChild(ta);
}
private function setupButtons():void {
b1 = new Button();
b2 = new Button();
b3 = new Button();

b1.width = 160;
b2.width = 160;
b3.width = 160;

b1.move(10,10);
b2.move(10,40);
b3.move(10,70);

b1.label = "Default Button";
b2.label = "Custom Styled Button";
b3.label = "Toggle Button";

b2.setStyle("textFormat", new TextFormat("Georgia"));

b3.toggle = true;

b1.addEventListener(MouseEvent.CLICK, buttonClick);
b2.addEventListener(MouseEvent.CLICK, buttonClick);
b3.addEventListener(MouseEvent.CLICK, buttonClick);

addChild(b1);
addChild(b2);
addChild(b3);
}
private function buttonClick(e:MouseEvent) {
var button:Button = e.target as Button;
ta.appendText(button.label + "\n");
}
}
}


found at the bottom of this page:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/controls/Button.html