I'm working on a project in Flash using Action Script 3.0. I converted a graphic to a button so that I can use it for various buttons throughout my project, but I can't figure out how to modify only the instance of the new button on the stage without modifying the whole class. For example, if my first button has a unique instance name and is called "Click Me" and I pull another instance of that button onto the stage and try to give it a new instance name and then relabel it to say "Next", it automatically modifies the "Click Me" button to say "Next" as well. Can anyone help me so I don't have to create a new class for every button that I make?
This behaviour is normal. The button you create that is in your library is not an instance. When you drag it onto the stage then you are creating the instance but if you change something, like replacing a textfield in it then you are changing the class.
One way to achieve what you want is to create a movieclip instead of a button. Then in your movieclip add a dynamic textfield inside. On all your movieclip instances (make sure it has a name if your dragging from library to stage), add the following code:
myBtn1.buttonMode = true;
myBtn2.buttonMode = true;
Now for each instance you can change the textfield by doing this assuming the dynamic textfield inside the clip is called txtLabel:
myBtn1.txtLabel.text = "hello";
myBtn2.txtLabel.text = "world";
If you want roll over states then you can do this, firstly add a keyframe for each state in the movieclip, do this on a seperate layer underthe textfield and give them a frame label for each section:
myBtn1.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver)
function onMouseOver(e:MouseEvent)
{
myBtn1.gotoAndStop("OVER_STATE");
//can use e.target.gotoAndStop("OVER_STATE") instead so that you can reuse the one
//function for all buttons. The above is just to illustrate the point.
}
Alternativly it may be possible to simply extend the SimpleButton class and then add a property to change a dynamic textfield that you create inside.