2 Replies Latest reply on Mar 12, 2008 11:55 AM by Mongolian Beef

    Formatting messages

    Mongolian Beef

      Was wondering if anyone knew a StringBuffer-like utility for Flex/AS3? I have an issue where I display error messages on my popup window and these messages vary in length. If they're long, it stretches the width of my popup. I would like to control these messages by putting line breaks after X number of characters. I wrote a utility function that tokenizes the message, but now would like to use something like StringBuffer (java) or StringBuilder(c#) to append the tokens with their appropriate line breaks. Currently I just append using String concatenation (which is bad). Any one have any ideas? Is there something built into the Flex API that can do this? Thanks!

        • 1. Re: Formatting messages
          levancho Level 3
          ActionScript is not java or C#

          var str1:String = new String("foo");
          var str2:String = "foo";
          Alert.show("str1===str2 "+(str1===str2)); // returns true

          while in java :

          String str1 = new String("foo");
          String str2 = "foo";
          System.out.println("str1==str2 "+(str1==str2)); // returns false,
          System.out.println("str1 equals str2 "+(str1.equals(str2)));// returns true;

          so when you say : "Currently I just append using String concatenation (which is bad)"

          its not entirely true,

          the only reason stringBuffer (in java) is efficient is because it does not increase heapsize by adding more and more string literals into the pool, but since ActionScript does not work that way you should not worry about it(i think).

          • 2. Re: Formatting messages
            Mongolian Beef Level 1

            Thanks for the reply. Not sure if this is still true but there seems to be performance hit with memory. Either way, I decided to format the messages on the server end instead...