Creating one button, each instance of which has different text.

I have a button (btn_1) with 3 states containing the text "January" in each of the 3 states, in which the over state is an MC (over_1) that stretches January from A/V zero to A/V 3.  Since the buttons will otherwise be identical, is there a way, through AS presumably, to just have each instance of the button  get the different text in all states?  The movie clip as well?

Thanks!

John
LVL 1
John CarneyReliability Business Tools Analyst IIAsked:
Who is Participating?
 
DavidTMooreCommented:
I have CS3 which will only let me backsave it to flash 8.  Here is the code I used though:

on the last frame of your main timeline (where the buttons reside)

stop();

//This defines the text for each button
btn_Res.buttonText.text = "button 1";
btn_test.buttonText.text = "button 2";
btn_test2.buttonText.text = "button 3"


//You will need one of these for each of the buttons
btn_Res.onPress = function(){
      getURL("http://www.google.com");
}


On the button itself:
on(rollOver){
      this.gotoAndPlay(2);
}
on(rollOut){
      this.gotoAndPlay(1);
}


Remember I changed the button to a movieclip so you can use actionscript within it, on the first frame (default state), for the 2nd frame (over state) simply change the color variable to 0xFFFFFF.  You will need to change your textbox within that movieclip to a dynamic textbox and name it buttonText for this to work.

stop();
myTextFormat = new TextFormat();
myTextFormat.bold = true;
myTextFormat.italic = true;
myTextFormat.color = 0x000000;
buttonText.setTextFormat(myTextFormat);



hope this helps
~David
0
 
DavidTMooreCommented:
You should be able to update via actionscript with the textformat class.

i.e. TextFormat.letterSpacing = X;

You will then need to apply the text format to the specific textbox.

Hope this helps

cheers
~David
0
 
John CarneyReliability Business Tools Analyst IIAuthor Commented:
I don't understand. That code looks like it would control the letter spacing of the movie clip. I need something that will change the text in each button instance.  For example, I could have an instance named "monday" and the code would tell that button to have the text "Monday" in the up and down states. The next instance would be named "tuesday", and the code would tell it to have the text "tuesday" in the up and down .  Etc., etc.

And hten the same process for the movie clip on the over state.

Thanks,
John
0
Ultimate Tool Kit for Technology Solution Provider

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 now.

 
DavidTMooreCommented:
ok, I misunderstood your question.  You will need to create a dynamic text field within your button.  Say for example dateText.  Then you will have to name each instance you place in your main timeline.  You would then be able to access that textbox by using:

instanceName.dateText.Text = "monday"

cheers
~David
0
 
John CarneyReliability Business Tools Analyst IIAuthor Commented:
Hi David,
I assume you mean that the text fields in the up and down states of the button should be dynamic text fields, perhaps one named UpText and the other DownText? Should they be left blank be left blank?
And what about the movie clip in the over state?
Right now I have the one instance of my button (btn_1), with the name "btn_Mon"  Exactly where does <instanceName.dateText.Text = "monday"> go? Is that part of the button's Action Script? If so, let's say that on release I want to goToAndStop at frame 26.  Could you give me that entire code? Otherwise I will probably not be able to fit the instanceName part in the right place.

Thanks!
John
0
 
DavidTMooreCommented:
Could you upload the file somewhere, im having a bit of a time understanding exactly what you're looking for and it would be a lot easier if I could take a look at it first hand.

cheers
~David
0
 
John CarneyReliability Business Tools Analyst IIAuthor Commented:
Here ya go, thanks for suggesting it. the actual button text will be things like Residential, Commercial, Design Development, etc.

Thanks,
John

http://www.designamania.com/websites/Textra/textra_beta2.fla
0
 
DavidTMooreCommented:
Take a look at this, I changed your button to a movieclip as this has a little bit more versatility.  You will see actionscript on the main timeline in the last frame, on the button itself, and within the button movieclip.  Please let me know if you have any questions.

www.verge-technology.com/textra_beta2.fla

cheers
~David
0
 
John CarneyReliability Business Tools Analyst IIAuthor Commented:
Hi David,

Do you have the option of saving this as MX2004?  I can't open the file. I neglected to say that I'm using that older version.

Thanks,
John
0
 
John CarneyReliability Business Tools Analyst IIAuthor Commented:
Excellent, David, thanks. By the way I'm going to be at a machine with Flash8 from 1 to 5pm California time. If you can save your file to Flash 8, then I can see exactly what you've done, which would be very helpful.
I'll see if I can actually implement the code you've given me, but it would really help me to see your file.

Thanks!
John
0
 
DavidTMooreCommented:
That file 'should' be saved as flash 8, im not on a PC with flash at the moment but if I remember correctly I backsaved it to 8 last night.

cheers
~David
0
 
John CarneyReliability Business Tools Analyst IIAuthor Commented:
Thanks, David.  I'll try it on my MX2004 file when I get home.

John
0
 
John CarneyReliability Business Tools Analyst IIAuthor Commented:
Hi David,

This is starting to work great except that the buttons (now movie clips) keep cycling through the three states, flashing black and white.
Also when I try to add AS to the first frame of the movie clip, it says that the current selection cannot have actions applied to it. Why is that and where exactly does this last bit of code go?
stop();
myTextFormat = new TextFormat();
myTextFormat.bold = true;
myTextFormat.italic = true;
myTextFormat.color = 0x000000;
buttonText.setTextFormat(myTextFormat);

I know this is super basic stuff, but I'm just not quite there yet.

Thanks!
John
0
 
DavidTMooreCommented:
ook, you will need to go into your library and convert the button to a movieclip, then you should be able to put the code in.  My guess is you just used the dropdown in the properties box to change it to a movieclip, you have to change it in the library as well.  That last bit of code will go on each frame of the button movieclip - that should stop the cycling.  Remember you'll only need the first two frames of the button.

cheers
~David
0
 
John CarneyReliability Business Tools Analyst IIAuthor Commented:
Awesome, David. Thanks!  You have really helped me immensely on this.  Thank you.
Also, I've asked a followup question here which I hope you can look at::
http://www.experts-exchange.com/Software/Photos_Graphics/Web_Graphics/Macromedia_Flash/Q_22974597.html

Cheers,
John
0
 
John CarneyReliability Business Tools Analyst IIAuthor Commented:
Great answer that was extremely helpful to me.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.