10 Replies Latest reply on Oct 10, 2007 6:28 AM by kglad

    Dynamic Button Text Not Selectable

    scrfix
      Hello,

      I am working with AS3/Flash CS3

      I have 5 buttons that are dynamically created. I have the buttons completed with tweens etc etc etc. It is time to put the text onto the buttons.

      How do you do the following:
      1. Create the button text
      2. Make it so the button text is on top of the button
      3. When someone rolls there mouse over the button the button still fade in and out.

      http://www.spectacularstuff.com/php-test/inprogress/home.php

      You can test out what I am talking about at the above link. I would do not wish to lose the button integrity but adding text on top. If you roll your mouse over the text, you will see the text is selectable.

      Thanks,

      Wayne
        • 1. Re: Dynamic Button Text Not Selectable
          kglad Adobe Community Professional & MVP
          if the textfield is a child or your button, assign your button's mouseChildren property to false.
          • 2. Re: Dynamic Button Text Not Selectable
            scrfix Level 1
            okay.....

            How do I know whether or not the textfield is a child of the button?
            How do I assign the button's mouseChildren property to false?

            Thanks,

            Wayne
            • 3. Re: Dynamic Button Text Not Selectable
              scrfix Level 1
              I am not sure how to tell the textfield to be a child of the button. How do you do this.

              I attempted the following however I receive errors:
              var ht:TextField = new TextField();
              ht.autoSize = TextFieldAutoSize.LEFT;
              ht.border = false;
              addChild(ht);
              ht.mouseChildren = false;
              • 4. Re: Dynamic Button Text Not Selectable
                kglad Adobe Community Professional & MVP
                how did you create your textfield?

                did you use actionscript to create it? if so, your textfield's probably not a child of your movieclip otherwise you would know you used something like yourMC.addChild(ht).

                did you create the textfield in the authoring environment? if so, it's a child of your movieclip if you created the textfield on the movieclip's timeline.
                • 5. Dynamic Button Text Not Selectable
                  scrfix Level 1
                  okay,

                  I have an issue then.
                  I have 1 MC (buttonMC) that hosts the effects for the button.
                  I have 5 buttons that I have dragged onto the main stage.
                  Each one has a separate instance name:
                  home, about, services, specials, contact

                  If I understand you correctly, I can go into the original buttonMC and create a new layer (Button Text) with a dynamic text field.
                  I can then give that dynamic text field an instance name (bt)
                  Inside that buttonMC I can add and actionscript layer (actions) that states bt.mouseChildren = false;

                  So, now if I have done all of this correctly I should have a dyanamic textfield with no text in it layered over a button that is not interfering with the mouse.

                  My issue is how do I dynamically add the correct text I want each instance of the button to display out to the real world.

                  I have an array already that you created a little while back:
                  var buttonA = ["home","about","services","specials","contact"];

                  However I would like the first letter to be capitalized when it actually displays the name.

                  Question 1: Am i correct in understanding what you are stating?
                  Question 2: If I do it that was how do I dynamically display the button names into that dynamic text field witht he first letter capitalized in each name?

                  Thanks,

                  Wayne
                  • 6. Re: Dynamic Button Text Not Selectable
                    kglad Adobe Community Professional & MVP
                    first, when you're on your button's timeline (and probably everywhere else) bt means nothing. use:

                    this.mouseChildren=false;

                    second, give your textfield an instance name, say tf.

                    third, you can then assign the text property to your textfields by using something like:

                    • 7. Re: Dynamic Button Text Not Selectable
                      scrfix Level 1
                      That works fantastic.
                      Where do I go in order to learn what actionscripts can be worked with that text. I know from other code that I can work with

                      (I named the instance btf for button text field)

                      btf.x = (number of pixels across here)
                      btf.y = (number of pixels down here)

                      What else can I do?
                      Example: Is there a btf.bold = true;??

                      What is the technical name of those items? In CSS those would be attributes. Does that hold true for AS3 as well?

                      Thanks,

                      Wayne
                      • 8. Re: Dynamic Button Text Not Selectable
                        kglad Adobe Community Professional & MVP
                        for a sketch of what you can do with every class in flash, use the help files (as 3.0 lang. and comp. usage/classes/the class you want to check). after clicking on a class, scroll to the bottom to look for examples of usage for ideas on how to apply some of the sketched methods and properties and events (and constructor).

                        if you do that, you'll see the textfield class has no bold property (or method). however, the textformat class has a bold property. you'll then need to do some further reading to see how to associate (use the setTextFormat() method of the textfield class) a textformat object with a textfield object.
                        • 9. Re: Dynamic Button Text Not Selectable
                          scrfix Level 1
                          I checked that out. Thank you... That helps out a lot!
                          I did attempt to work with the bolded text and then found out that apparently in order to work with the TextFormat I need to have created the textfield in AS3 and not drawn out in the movie symbol.

                          I attempted this[buttonA ].btf.bold = true; and it came back with an error.

                          I also attempted btf.bold = true; and that came back as btf not found?

                          Then I saw in the examples that they were creating the textfields in AS3 before working with the textformat. Is this correct or am I just working with this incorrectly?

                          Wayne
                          • 10. Re: Dynamic Button Text Not Selectable
                            kglad Adobe Community Professional & MVP
                            you have a number of errors. all the following applies to as2 and as3, both:

                            first, you don't need to create a textfield with actionscript in order to assign it a bold font. you can create the textfield in the authoring environment and with actionscript and you can assign it a bold font in the authoring environment and with actionscript.

                            second, it looks like you're trying to assign a bold property to a textfield. textfields have no bold property. again, it's the textformat class that you need to work with to assign a bold font using actionscript.

                            the examples may show creating textfields before working with textformat because it's not necessary to specify a textformat instance for a textfield created with actionscript. it will have the default textformat instance.