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!
formiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rascalpantsCommented:

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
0
formiAuthor Commented:
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 ...
0
rascalpantsCommented:
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

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

formiAuthor Commented:
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)?
0
rascalpantsCommented:
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
0
formiAuthor Commented:
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?
0
rascalpantsCommented:
buttonMode = true should make that work...

but you can also use...

btnName.useHandCursor = true;

 
rp / ZA

0
formiAuthor Commented:
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?
0
rascalpantsCommented:

actually, all you really need is this...

btn.buttonMode = true;
btn.mouseChildren = false;

and then just make sure you don't have the text box enabled for cursor selection... this is in the properties panel and looks like this...  A|B  next to  <>

you shouldn't need to use useHandCursor =  true if you disable the chidren of the object...


rp / ZA
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
formiAuthor Commented:
Great, you are a really an expert! Thanks a lot!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development Software

From novice to tech pro — start learning today.