Link to home
Start Free TrialLog in
Avatar of formi
formiFlag for Switzerland

asked on

Flash: how to change text of button with ActionScript?

Flash CS4: if I make a simple dynamic Text-field an name the instance (i.e. mytext) I can change the text (or textstyle) with mytext.text = "abc". I need to change the text (and textstyle) of a simpl button. So if I convert the text to a symbol I can not change the text. How can I do this? Exemple? Thanks for any tip!
Avatar of rascalpants
rascalpants
Flag of United States of America image


you give the new symbol and instance name in the properties panel, and then you reference it like this...

newNameOfInstance.mytext.text = "abc";


rp / ZA
Avatar of formi

ASKER

that's what I tried but it doesn't work:

I createt a text-field (dynamic-text) and named the instance "mytext"
then I convert this to a symbol named "sym1"
now I make an instance of that symbol and name it "newNameOfInstance"
in the action-script I write the following code:

newNameOfInstance.mytext.text = "abcd";

and I get the error: ReferenceError: Error #1069: property mytext for flash.display.SimpleButton not found ...
are you sure you are giving the item an "Instance name" and not just naming the symbol? when you turn it into a symbol, you name it... then in the properties panel, you give it an instance name.
one other thing...  is your symbol a movieclip or a button?  you should never use buttons... they are not needed... you should be using movieclips


rp / ZA

Avatar of formi

ASKER

That's true. I use buttons and if I change it to a movieclip it works. But I want that when I move the cursor on the symbol that I get the "hand-cursor" and can catch "onclick-events" as with buttons. How I have to do this (I'm new in flash-programming)?
here is the standard for AS 3.0 button (movieclips)

btnName.addEventListener( MouseEvent.CLICK, on_Click);
btnName.addEventListener( MouseEvent.ROLL_OVER, on_RollOver);
btnName.addEventListener( MouseEvent.ROLL_OUT, on_RollOut);
btnName.buttonMode = true;

function on_Click( evt:Event ):void
{
   trace("you clicked --> " + evt.target.name);
}

function on_RollOver( evt:Event ):void
{
   trace("you rolled over --> " + evt.target.name);

}

function on_RollOut( evt:Event ):void
{
   trace("you rolled out of --> " + evt.target.name);

}


hope this helps...


rp / ZA
Avatar of formi

ASKER

nearly everything ok except the user can not see the "hand"-cursor and he doesn't know that this is a button. How to solve this?
buttonMode = true should make that work...

but you can also use...

btnName.useHandCursor = true;

 
rp / ZA

Avatar of formi

ASKER

the aim is not far: I have to set both, buttonMode and useHandCursor.  my last question: that works (I made a MovieClip with a rectangle and a text) in the part of the rectangle but not in the part of the text-field. Have aou a solution for that?
ASKER CERTIFIED SOLUTION
Avatar of rascalpants
rascalpants
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of formi

ASKER

Great, you are a really an expert! Thanks a lot!!