10 Replies Latest reply on Jan 17, 2008 2:39 PM by Newsgroup_User

    Loading Special Characters

    Berall
      Hey everyone, hopefully this is really easy. I have a really simple easy quiz that pulls questions off a .txt file. Trouble is, whenever a question uses the special character "&", flash doesn't display it. Almost as if it isnt there. If I push things further, it actually displace a space, or in some cases seems to delete whatever letter was in front of it!?

      Does anyone know whats going on? Does anyone know what I need to do to the data sheet (or flash) to let it full up % and other special characters like $, #, or @ ??
        • 1. Re: Loading Special Characters
          Level 7
          Here's a function from Andrew Sinning (on Flash-Coders) that should help:

          function htmlAmpCharsToFlashHtmlAmpChars(str:String):String {

          str = str.split(" ").join(" ");

          str = str.split(" ").join(" ");

          str = str.split("–").join("–");

          str = str.split("—").join("—");

          str = str.split("—").join("—");

          str = str.split("‘").join("‘");

          str = str.split("’").join("’");

          str = str.split("“").join("“");

          str = str.split("⁄").join("⁄");

          str = str.split("€").join("€");

          str = str.split("™").join("™");

          str = str.split("←").join("←");

          str = str.split("→").join("→");

          str = str.split("←").join("←");

          str = str.split("→").join("→");

          str = str.split("↔").join("↔");

          str = str.split("⇐").join("⇐");

          str = str.split("⇒").join("⇒");

          return str;

          }


          --
          Dave -
          Head Developer
          http://www.blurredistinction.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/


          • 2. Re: Loading Special Characters
            Berall Level 1
            Umm....Wow. thats....thats really something. Do I just put it at the begging of the flash file? Lastly, the flash file will play by itself, not in an HTML browser. Will it still work without it?
            • 3. Re: Loading Special Characters
              Berall Level 1
              Umm....Wow. thats....thats really something. Do I just put it at the begging of the flash file? Lastly, the flash file will play by itself, not in an HTML browser. Will it still work without it?
              • 4. Re: Loading Special Characters
                kamckng Level 1
                You would put that anywhere in your flash file. Then when you load in the txt file, call that function and psas the text you loaded into it. That function takes all the &'s and changes them into the normal &'s that flash can display
                • 5. Re: Loading Special Characters
                  kamckng Level 1
                  Oh and make sure to set it equal to a string var... such as

                  var displayText:String = htmlAmpCharsToFlashHtmlAmpChars(<loaded text>);
                  • 6. Re: Loading Special Characters
                    Level 7
                    Hi Berall,

                    When you load up data, it's assumed to be URL encoded. That means that
                    special characters like the ampersand (&) are used to denote data sections
                    rather than being taken literally. In this case, the ampersand denotes the
                    beginning of a variable in the same way as if you had included it in a URL:
                    http://www.someserver.com/script.php?var1=some_data&variable2=some_other_data

                    There are two simple solutions to this:

                    1. Replace all occurances of "&" with "&amp;". When teh data is loaded,
                    apply the function decode(loadedText) on it.
                    2. Create your own parser. Decide which character (or set of characters)
                    will represent an ampersand. A simple function like this will parse it out
                    and return the correct string:

                    //assume the variable "loadedtext" is your loaded data
                    var ampersandRepresentation:String="%amp%"; //Or however you want to
                    represent it
                    var realString:String=new String(loadedtext); //We just make sure it's a
                    real string object here so that we can use the required string class methods
                    var returnString:String=realString.split(ampersandRepresentation).join("&");
                    //returnString now contains the correct ampersand-ed string

                    If you're wondering how this is accomplished, basically the "realString"
                    string is split up (the split command) into a numbered array anywhere where
                    the string is found (in this case the '%amp%'...but this can be anything you
                    want). The array is then joined up again, in sequence, using the ampersand
                    character to join the elements. Again, you could replace this with any
                    character or string.

                    This is effective and *fast*...it uses low-level Flash routines to
                    transform the data. You could use other routines to analyze the string one
                    character at a time but it's processor intensive and you end up with the
                    same result.

                    Hope this helps.

                    Regards,
                    Patrick Bay
                    BAY NEW MEDIA

                    "Berall" <webforumsuser@macromedia.com> wrote in message
                    news:fmgia6$clg$1@forums.macromedia.com...
                    > Hey everyone, hopefully this is really easy. I have a really simple easy
                    > quiz
                    > that pulls questions off a .txt file. Trouble is, whenever a question uses
                    > the
                    > special character "&", flash doesn't display it. Almost as if it isnt
                    > there. If
                    > I push things further, it actually displace a space, or in some cases
                    > seems to
                    > delete whatever letter was in front of it!?
                    >
                    > Does anyone know whats going on? Does anyone know what I need to do to the
                    > data sheet (or flash) to let it full up % and other special characters
                    > like $,
                    > #, or @ ??
                    >

                    • 7. Re: Loading Special Characters
                      Berall Level 1
                      wow! This is all flying over my head so high! I have a lot to learn. And here I thought it would be a simple little click here or a tiny piece of code there....
                      • 8. Re: Loading Special Characters
                        Level 7
                        Actually, this operation is fairly simple. Most of the work is done by
                        Flash. As for the data type, that's a left-over from earlier Flash versions
                        where everything was assumed to be loaded as URL-encoded. In fact, most
                        developers avoid this format because maintaining it is clunky. It's also
                        challenging to adapt it to broader projects where data plays a more central
                        role.

                        If you get a chance, I would highly recommend that you start working with
                        XML. The format is extremely flexible and infinitely easier to work with
                        than URL encoded variables. In ActionScript 3, XML handling routines are
                        even better (more robust, faster, etc.). For example, an entire search
                        "engine" for XML data has been added to Flash 9/AS3 called XPath that simply
                        doesn't exist for URL-encoded data.

                        I don't mean to imply that URL-encoded data doesn't have its place. When
                        loading up a web page, for example, server-side scripts can be greatly
                        enhanced by including data in requests (for example, page number, search
                        parameters, etc.) However, so much data on the web today is stored as XML
                        (RSS, XMLs, SVG, new generation of Microsoft Office files and PDFs),
                        including two-way server interactions (SOAP, REST), that it's really
                        worthwhile to learn the format and how to work with it in Flash. It will
                        instantly open up so many possibilities for you and your applications. And
                        in case you haven't tried it yet, there's a new technology just around the
                        bend called the Adobe Integrated Runtime that allows your Flash content to
                        run as a desktop application (being able to do things like read files from
                        the file system, spawn new windows, etc.), and much of this technology is
                        XML-based.

                        And I will stop rambling now :)

                        Feel free to drop me a line if you want more info: patrick (AT) baynewedia
                        (DOT) com

                        Regards,
                        Patrick Bay
                        BAY NEW MEDIA

                        "Berall" <webforumsuser@macromedia.com> wrote in message
                        news:fmilbg$ndu$1@forums.macromedia.com...
                        > wow! This is all flying over my head so high! I have a lot to learn. And
                        > here I thought it would be a simple little click here or a tiny piece of
                        > code there....

                        • 9. Re: Loading Special Characters
                          Level 7
                          >>However, so much data on the web today is stored as XML ...

                          FYI, data is not typically stored as XML - but merely presented as such. It
                          is stored in databases - and it is still much quicker and easier to just
                          quiery the database as opposed to first generating XML from the database,
                          then loading and parsing it. In some cases, that's all you get, but when you
                          have a choice XML is typically not best solution.

                          --
                          Dave -
                          Head Developer
                          http://www.blurredistinction.com
                          Adobe Community Expert
                          http://www.adobe.com/communities/experts/


                          • 10. Re: Loading Special Characters
                            Level 7
                            Hi Dave,

                            Well, you have a point, but I don't have any statistics on that so I
                            couldn't argue it either way. All I have is practical experience. I do know,
                            for example, that the vast majority of products I've worked on (especially
                            for smaller clients) has had data stored as XML (not extrapolated to but
                            actually stored as). In cases where data sorting was an issue, we would
                            create databases and have them generate some generic XML wrapper, but this
                            wasn't always the case or even necessary most of the time. Most clients
                            don't really have data-intensive operations, at least not on the front end.
                            And this was in the days of ActionScript 2.0 so much of the XML code was
                            still hand-tooled and not exactly super-fast.

                            XML is certainly bulky compared to binary serialization formats like
                            AMF, for example, but when considering extensibility, usability, adoption,
                            and ease-of-use, I think you'd be hard-pressed to find anything better. I
                            have written 128-bit encryption systems, low-level hardware drivers, and
                            created binary data formats, so I wouldn't consider myself binary-shy, but I
                            nonetheless choose XML because I believe that the pros outweigh the cons.
                            XML parsing and searching routines in most languages these days are written
                            with, or at least close to, assembly or machine-code level speed (i.e.
                            fast), so the format is a great one for sheer rapid application development
                            at decent performance. Also, it's hard to argue with XML's merit when so
                            many key players are adopting it as a standard (Microsoft Office, Open
                            Office, Adobe, etc.)

                            I do see what you're getting at and you do have a valid point, but I
                            would disagree and say that XML is typically the best option (at least that
                            has been my experience).

                            Regards,
                            Patrick Bay
                            BAY NEW MEDIA

                            "DMennenoh **AdobeCommunityExpert**" <dave@blurredistinction.com> wrote in
                            message news:fmj4ac$ahm$1@forums.macromedia.com...
                            >>>However, so much data on the web today is stored as XML ...
                            >
                            > FYI, data is not typically stored as XML - but merely presented as such.
                            > It is stored in databases - and it is still much quicker and easier to
                            > just quiery the database as opposed to first generating XML from the
                            > database, then loading and parsing it. In some cases, that's all you get,
                            > but when you have a choice XML is typically not best solution.
                            >
                            > --
                            > Dave -
                            > Head Developer
                            > http://www.blurredistinction.com
                            > Adobe Community Expert
                            > http://www.adobe.com/communities/experts/
                            >