Solved

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

Posted on 2007-11-19
16
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
16 Comments
 
LVL 4

Expert Comment

by:DavidTMoore
ID: 20316834
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
ID: 20316995
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
ID: 20317031
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:gabrielPennyback
ID: 20317478
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
ID: 20317509
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
ID: 20317578
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
ID: 20317684
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
ID: 20318094
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
 
LVL 4

Accepted Solution

by:
DavidTMoore earned 500 total points
ID: 20319492
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
ID: 20322293
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
ID: 20322310
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
ID: 20324002
Thanks, David.  I'll try it on my MX2004 file when I get home.

John
0
 
LVL 1

Author Comment

by:gabrielPennyback
ID: 20324951
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
ID: 20324988
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
ID: 20325337
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
ID: 31410038
Great answer that was extremely helpful to me.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.

691 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