all groups > flash actionscript > june 2004 >
You're in the

flash actionscript

group:

covert textField to button



covert textField to button krl
6/18/2004 11:05:17 PM
flash actionscript: So everyone knows about the capability in Flash to convert a text field into a
symbol (more specifically a button). But does anyone know how to do this
behavior in action script. It would be very useful for me at the moment. Thanks
a whole lot.
So this is what I've got:
createTextField("testF",1,0,0,500,500)
testF.text = "test text"
mybutt = new Button
mybutt = testF
trace(typeof (mybutt))

Doesn't work though...
Re: covert textField to button MechaFlasher
6/18/2004 11:41:57 PM
Typeof will not tell you if your object is a button or textfield. It will only
return "object".

And you're not actually converting the text field itself into a symbol, it's
just creating a symbol and adding that text field inside it.

So, in your actionscript you'd have to create an empty movie clip, then create
a text field inside that. Then you would define your onPress, onRelease, etc
methods on that movieclip:



_root.createEmptyMovieClip("mcButton", 1);
_root.mcButton.createTextField("testF", 1, 0, 0, 500, 500);
_root.mcButton.testF.text = "test text";
_root.mcButton.onPress = function()
{
trace("mcButton pressed!!");
};
Re: covert textField to button krl
6/18/2004 11:57:32 PM
MechaFlasher,
You my friend, are freakin' cool.
Do you know if there is a way to auto size the textfield to only be as tall and wide as the text itself?
krl
Re: covert textField to button MechaFlasher
6/19/2004 12:09:22 AM
No prob. There is a way to resize to fit the text:

myTextField._width = myTextField.textWidth;
myTextField._height = myTextField.textHeight;

or set autoSize before you put text into it:

myTextField.autoSize = "left";
Re: covert textField to button krl
6/21/2004 3:47:14 PM
MechaFlasher,
You have once again shown that you are "freakin' cool".
Thanks so much for your help.
AddThis Social Bookmark Button