Solved

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

Posted on 2007-11-19
16
204 Views
Last Modified: 2010-04-21
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
0
Comment
Question by:gabrielPennyback
  • 9
  • 7
16 Comments
 
LVL 4

Expert Comment

by:DavidTMoore
Comment Utility
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
 
LVL 1

Author Comment

by:gabrielPennyback
Comment Utility
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
 
LVL 4

Expert Comment

by:DavidTMoore
Comment Utility
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
 
LVL 1

Author Comment

by:gabrielPennyback
Comment Utility
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
 
LVL 4

Expert Comment

by:DavidTMoore
Comment Utility
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
 
LVL 1

Author Comment

by:gabrielPennyback
Comment Utility
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
 
LVL 4

Expert Comment

by:DavidTMoore
Comment Utility
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
 
LVL 1

Author Comment

by:gabrielPennyback
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 4

Accepted Solution

by:
DavidTMoore earned 500 total points
Comment Utility
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
 
LVL 1

Author Comment

by:gabrielPennyback
Comment Utility
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
 
LVL 4

Expert Comment

by:DavidTMoore
Comment Utility
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
 
LVL 1

Author Comment

by:gabrielPennyback
Comment Utility
Thanks, David.  I'll try it on my MX2004 file when I get home.

John
0
 
LVL 1

Author Comment

by:gabrielPennyback
Comment Utility
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
 
LVL 4

Assisted Solution

by:DavidTMoore
DavidTMoore earned 500 total points
Comment Utility
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
 
LVL 1

Author Comment

by:gabrielPennyback
Comment Utility
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
 
LVL 1

Author Closing Comment

by:gabrielPennyback
Comment Utility
Great answer that was extremely helpful to me.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now