7 Replies Latest reply on Dec 7, 2010 2:33 PM by GordonSmith

    How does data formatting work in AS3 ?

    VirtualCoder Level 1

      In some of my more legacy languages, I could convert various data types to a nicely formatted string.

      For example "!x(20)" would capitalize the first letter of string.

      "$>>>,>>9.99 would give me $1.23

      (999) 999-9999 would convert an integer or a string into a nice looking phone number

      etc, etc

       

      How is this sort of thing best done in AS 3?

       

      In addition, is there a way to feed such masks to text input controls so that (for example) a telephone number can be entered within an already visible (  )  -

       

      Thaks,

      VC

        • 1. Re: How does data formatting work in AS3 ?
          Flex harUI Adobe Employee

          The default controls don't do masked input, but some third-party controls

          do.

           

          There is some formatting support in StringFormatter and StringUtil

          • 2. Re: How does data formatting work in AS3 ?
            VirtualCoder Level 1

            I found StingUtil static class and even DateFormatter but for life of me I can not find StringFormatter anywhere or rather what the import statement should look like. With all the bells and whistles in FlashBuilder - how come it does so poorly the most basic of things - like finding standard Adobe classes ?!?

             

            Even tried googling AS3 and/or Flex StingFormatter and all sorts of junk comes up but nothing that show use of this class !

            • 3. Re: How does data formatting work in AS3 ?
              VirtualCoder Level 1

              Maybe somebody can go here and try and find it ;))))))))))))

              I am really, seriously starting to loose my patience with adobe products because the toughest parts they have done ohhh so well - extremely well ... and then they totally mess it up on little **** details like this - nevertheless details which are the beef - without which all that other sizzle is pretty much useless ... as useless as StringFormatter is to me right now - since I can not do the simplest damn thing with it and that is to find it !!!!!!!!!!!!!!!!!!!!!!!

              • 4. Re: How does data formatting work in AS3 ?
                GordonSmith Level 4

                All formatters are in the mx.formatters package.

                 

                Gordon Smith

                Adobe Flex SDK Team

                • 5. Re: How does data formatting work in AS3 ?
                  Devtron Level 3

                  I have the ADOBE FLEX 4 Framework posters sitting in front of my face and I do not see a StringFormatter class.

                   

                  I also opened the PDF version and searched for "StringFormatter" and did not find it.

                   

                  Maybe its another top secret FLEX hidden feature I really doubt that though.

                   

                  Now I am curious if StringFormatter even exists in the FLEX Framework???

                   

                  I see  StringUtil, StringValidator on the framework poster.

                   

                  Digging into source code, I see StringTools, which is poorly documented.

                   

                  Not seeing a StringFormatter though

                  • 6. Re: How does data formatting work in AS3 ?
                    Devtron Level 3

                    Ahhh. you need:

                     

                    mx.formatters.Formatter;

                     

                    var myFormatter:Formatter;

                    myFormatter.format(objecthere);

                    • 7. Re: How does data formatting work in AS3 ?
                      GordonSmith Level 4

                      mx.formatters.StringFormatter does exist, but it turns out to be an intentionally undocumented and un-codehinted class. A comment on the class declaration says "This class is used internally by other formatters, and is typically not used directly."

                       

                      The type of numeric formatting that VirtualCoder was looking for is similar to what NumberFormatter does, and this IS a documented and code-hinted class. However, it doesn't offer as many formatting options as VirtualCoder expects.

                       

                      Although Flex's formatting capabilities are pretty basic, providing better ones hasn't been high on Flex developers' lists of improvement requests. I'm not sure whether that means that most developers get along OK with the basic support, write their own sophisticated subclasses of Formatter, or use some 3rd-party ActionScript formatting library.

                       

                      Gordon Smith

                      Adobe Flex SDK Team