8 Replies Latest reply on Jul 20, 2007 8:29 AM by Newsgroup_User

    How to work with TextFormat Class?

    jcarruth@earthlink.net
      This code will allow you to enter text in a box, click submit, and have that text display somewhere else on the screen. How can I add in the TextFormat class to allow me to format the text that's displayed?

      Thanks,
      jcarruth
        • 1. Re: How to work with TextFormat Class?
          kglad Adobe Community Professional & MVP
          create a textformat object, assign its properties and then either assign your textfield's defaultTextFormat property to be your textformat object or use your textfield's setTextFormat() method.
          • 2. Re: How to work with TextFormat Class?
            Level 7
            Hi jcarruth,

            Working with TextFormat is quite simple. It works much like the
            TextField in that you assign properties to the object, and then you
            simply set the format on the text field. Here's a sample using your own
            code:
            var body_txt:TextField = new TextField();
            var format:TextFormat=new TextFormat();
            var yourName:String;
            body_txt.x = 98;
            body_txt.y = 66;
            format.color=0xFF0000;
            format.font="Arial";
            body_txt.autoSize = TextFieldAutoSize.LEFT;
            submit_btn.addEventListener(MouseEvent.CLICK, onClick);
            function onClick(event:MouseEvent):void
            {
            addChild(body_txt);
            yourName = name_txt.text;
            board_txt.text = yourName;
            body_txt.text = "Hi " + yourName + "! Here's your custom board.";
            body_txt.setTextFormat(format);
            }

            There are a few different ways to apply a format to a text field. This
            way simply applies it to the content of the text field directly. Extra
            parameters can be used to apply the format of only a portion of the
            text. There is also a method named 'setNewTextFormat' that applies the
            format to only to text added after that call.

            Text formats, especially those using font embedding, can be a bit
            tricky. I have a pretty robust API for ActionScript 2 (almost ported
            fully to AS3) which makes short work of this kind of stuff. I still have
            to write documentation and all that kind of stuff but I can give you
            very specific samples for text-related stuff if it's giving you trouble
            using the regular method.

            Regards,
            Patrick
            BNM

            jcarruth@earthlink.net wrote:
            > This code will allow you to enter text in a box, click submit, and have that
            > text display somewhere else on the screen. How can I add in the TextFormat
            > class to allow me to format the text that's displayed?
            >
            > Thanks,
            > jcarruth
            >
            > var body_txt:TextField = new TextField();
            > var yourName:String;
            > body_txt.x = 98;
            > body_txt.y = 66;
            > body_txt.autoSize = TextFieldAutoSize.LEFT;
            > submit_btn.addEventListener(MouseEvent.CLICK, onClick);
            > function onClick(event:MouseEvent):void
            > {
            > addChild(body_txt);
            > yourName = name_txt.text;
            > board_txt.text = yourName;
            > body_txt.text = "Hi " + yourName + "! Here's your custom board.";
            > }
            >
            • 3. Re: How to work with TextFormat Class?
              jcarruth@earthlink.net Level 1
              Thanks, Patrick B.

              kglad's answer may have worked for me if I wasn't brand new to this, and could take a line of instructions and turn it into working code. Seeing the answer right there in front of me helps a great deal. Then I study the code I gave you and see the differences in what you did, and learn it that way. But at least I know I that what I am looking at is working code, and so the study pays off.

              I am learning ActionScript 3 from Lynda.com, where the instructor says, "If you want to add formatting to this code, just review the movie on it from the last chapter." No example of how the two are integrated, and so I try it and get many errors. I am going to have to learn this at first by studying working code examples for a while, until I can put it together properly for myself.

              jcarruth
              • 4. Re: How to work with TextFormat Class?
                Level 7
                I hear you. I've spent a lot of my "learning" time dealing with the same
                sort of vague instruction. There comes a point where you can figure
                stuff out by yourself but it takes some time of slugging it out before
                you hit those big "aha!" moments.

                May offer a personal invitation to you? I'm setting up forums on my
                company site: baynewmedia.com
                It's intended as a place to discuss my Flash API; a collection of
                routines to make programming *much* easier and robust. But, I would be
                pleased to answer your questions about any Flash related topics in
                exchange for your patronage. And by all means, invite anyone you like :)

                Regards,
                Patrick

                Thanks,
                Patrick

                jcarruth@earthlink.net wrote:
                > Thanks, Patrick B.
                >
                > kglad's answer may have worked for me if I wasn't brand new to this, and could
                > take a line of instructions and turn it into working code. Seeing the answer
                > right there in front of me helps a great deal. Then I study the code I gave you
                > and see the differences in what you did, and learn it that way. But at least I
                > know I that what I am looking at is working code, and so the study pays off.
                >
                > I am learning ActionScript 3 from Lynda.com, where the instructor says, "If
                > you want to add formatting to this code, just review the movie on it from the
                > last chapter." No example of how the two are integrated, and so I try it and
                > get many errors. I am going to have to learn this at first by studying working
                > code examples for a while, until I can put it together properly for myself.
                >
                > jcarruth
                >
                • 5. How to work with TextFormat Class?
                  jcarruth@earthlink.net Level 1
                  Patrick,

                  Thank you for the invitation. I will definitely check it out. Not sure I want to venture into a new API when I am still so shaky with Flash and AS 3 at this point, but maybe down the line it will make more sense to me.

                  I have a suggestion for other newbies who have to learn things the hard way without much in the way of explanation. I first tried Joey Lott's "ActionScript 3.0 in Flex Builder Essential Training" before I received my copy of Flash CS3, and found that I couldn't get the Flex SDK to work (they've removed this suggestion from Lynda.com after I complained that I couldn't get it to work),

                  However, after going through Todd and Rich's Flash CS3 material on Lynda.com, and finding the kind of non-explanatory approach only goes so far, I returned to Joey's title now that I have a place to put my code other than Flex 2, and he DOES have a lot of material early in the course where he actually explains things like Variables, Expressions and operators, Conditional statements, Looping statements Arrays, Understanding objects, Writing classes. Hopefully after going through these tutes I will have a better grasp on where to put things and why, and not just aping code I see and praying that enough of that will sink in over time and begin to make sense.

                  Thanks,
                  jcarruth
                  • 6. Re: How to work with TextFormat Class?
                    Level 7
                    Hi again,

                    Interesting that you should bring this up. I was tossing around the
                    idea of putting up video/audio tutorials for people who are starting out
                    with ActionScript. I've even found hardcore Java developers shaking
                    their head because AS can be very....unique. My time is kind of limited
                    so I was mulling what types of tutorials could be used. Basically it's a
                    choice of learning tutorials...no specific examples other than going
                    through technique step by step. The other choice was simply to give
                    tutorials on very specific subjects ("I want to make X with a spinning
                    Y"). Any suggestions?

                    I know how you feel. I've butted heads with people in these forums many
                    times in the past. Incredibly, some people got into arguments with me
                    about code I developed (not knowing I wrote it) and stating completely
                    wrong things--even to the point of telling me that the developer told
                    them I was wrong (!) These people were usually rude to boot. Well,
                    jcarruth, you won't get that from me. I'm here to help people out with
                    patience and hopefully understanding. If I don't want to do that or I
                    don't have time...I won't! I'm not going to be a jerk about it and
                    pretend that I'm spilling my pearls before swine or some such stuck-up
                    nonsense. I've programmed in a variety of languages: Java, C#, PHP,
                    JavaScript, Pascal ... ActionScript is *definitely* the most challenging
                    and quirky. Trust me when I tell you, though, that ActionScript 3.0 is
                    powerful to a degree that's unprecedented in any client-side technology.
                    Not only can it do stuff in the browser that basically nothing else even
                    comes close to, you can now start to write desktop apps with AIR.
                    Getting into Flash now is about the next best thing since sliced bread
                    ;) I'm getting permissions from the authors of other open-source
                    libraries to include them in my API so learning rudimentary operation of
                    it should open up a WHACK of new stuff. I'm not replacing or changing
                    their code, just providing a sort of unified bridge so that once you
                    know how to use the API, you can automatically use all these other
                    things too. Papervision3D just gave me the nod to allow packaging their
                    3D libraries with the BNMAPI. Have you seen the demos
                    ( http://blog.papervision3d.org/tag/demos/)? That's an awesome
                    technology. I have a rudimentary SVG interpreter built into the
                    API...another supported format that you just won't find anywhere else,
                    then there's JSON, 128-bit encryption classes, JavaScript injection
                    system....the list is getting pretty long and there's no end in sight.

                    Well, drop by my forums and post away. It's a bit quieter there and I
                    will guarantee that it's friendly. Plus I have a lot more leeway in the
                    content I can post there so you should be able to get much better answers.

                    And that goes for the lot of ya!

                    Patrick

                    http://www.baynewmedia.com/

                    jcarruth@earthlink.net wrote:
                    > Patrick,
                    >
                    > Thank you for the invitation. I will definitely check it out. Not sure I want
                    > to venture into a new API when I am still so shaky with Flash and AS 3 at this
                    > point, but maybe down the line it will make more sense to me.
                    >
                    > I have a suggestion for other newbies who have to learn things the hard way
                    > without much in the way of explanation. I first tried Joey Lott's "ActionScript
                    > 3.0 in Flex Builder Essential Training" before I received my copy of Flash CS3,
                    > and found that I couldn't get the Flex SDK to work (they've removed this
                    > suggestion from Lynda.com after I complained that I couldn't get it to work),
                    > and the folks on the Adobe Flex 2 Forum site are VERY hostile to newbies (very
                    > common with programeratti of all flavors, not just Flex, so I am not singling
                    > anyone out here - you're ALL mean to us newbies - admit it!), so I bailed. But
                    > to give you all a break, who needs a needy newbie? I understand your hostility.
                    > Don't appreciate it, but I understand it completely.
                    >
                    > However, after going through Todd and Rich's Flash CS3 material on Lynda.com,
                    > and finding the kind of non-explanatory approach only goes so far, I returned
                    > to Joey's title now that I have a place to put my code other than Flex 2, and
                    > he DOES have a lot of material early in the course where he actually explains
                    > things like Variables, Expressions and operators, Conditional statements,
                    > Looping statements Arrays, Understanding objects, Writing classes. Hopefully
                    > after going through these tutes I will have a better grasp on where to put
                    > things and why, and not just aping code I see and praying that enough of that
                    > will sink in over time and begin to make sense.
                    >
                    > If any of the Programeratti out there wish to recommend very basic books that
                    > actually explain ActionScript 3.0 and not just assume you've been doing it for
                    > years, I promise to stay out of your hair, not ask dumb questions, and will
                    > actually read the book if I can.
                    >
                    > Thanks,
                    > jcarruth
                    >

                    --
                    http://www.baynewmedia.com
                    Faster, easier, better...ActionScript development taken to new heights.
                    Download the BNMAPI today. You'll wonder how you ever did without it!
                    Available for ActionScript 2.0/3.0.
                    • 7. How to work with TextFormat Class?
                      jcarruth@earthlink.net Level 1
                      Patrick,

                      You might want to read my posts in http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=15&catid=288&threadid =1285992&enterthread=y

                      It deals with the programeratti issue. Someone accused a newbie, who was frustrated with learning Flash and ActionScript, of not being able to follow instructions. Puleeese! How in the hell do they know this?

                      It's sure to anger a few people, who are just plain intolerant to begin with. Does my intolerance of their intolerance make me intolerant as well? Well, I guess so. It's a 'tude we can do without, in my opinion.

                      jcarruth

                      P.S. I just dialed by there and saw your post. Looks like you have checked it already! I wasn't refering to you either. The ones who hate newbies know who they are.
                      • 8. Re: How to work with TextFormat Class?
                        Level 7
                        You got that right! One thing I never understood is why people would
                        join this forum and answer questions with the appearance of not wanting
                        to be involved. Puleeese is right :)

                        Patrick

                        jcarruth@earthlink.net wrote:
                        > Patrick,
                        >
                        > You might want to read my posts in
                        > http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=15&catid=28
                        > 8&threadid=1285992&enterthread=y
                        >
                        > It deals with the programeratti issue. Someone accused a newbie, who was
                        > frustrated with learning Flash and ActionScript, of not being able to follow
                        > instructions. Puleeese! How in the hell do they know this?
                        >
                        > It's sure to anger a few people, who are just plain intolerant to begin with.
                        > Does my intolerance of their intolerance make me intolerant as well? Well, I
                        > guess so. It's a 'tude we can do without, in my opinion.
                        >
                        > jcarruth
                        >

                        --
                        http://www.baynewmedia.com
                        Faster, easier, better...ActionScript development taken to new heights.
                        Download the BNMAPI today. You'll wonder how you ever did without it!
                        Available for ActionScript 2.0/3.0.