7 Replies Latest reply on Jan 1, 2008 7:36 AM by manofspirit

    \n parameter is not working

    manofspirit Level 1
      Hello Buddies
      iM having a problem in a TEXTAREA that has a bindable variable, named desc
      <mx:TextArea text="{desc}" />

      following code works well and text Area detects [\n] as a NEW LINE Parameter.
      private var sDes:String = "CorelDraw\nIllustrator";

      and shows it
      [output]
      CorelDraw
      Illustrator

      But when i capture abv String from a xmlfile`s tag <desc>CorelDraw\nIllustrator</desc>
      it doesnt detect it as a newline parameter and simply shows it as
      [output]
      CorelDraw\nIllustrator

      How can i make him understand \n parameter when it reads from an xml file?
        • 1. Re: \n parameter is not working
          VarioPegged Level 2
          Use the XML new line character: &#xA;

          So your XML element would look like this:
          <desc>CorelDraw&#xA;Illustrator</desc>

          I wouldn't recommend forming your data like this though. It'd probably be best to set each value separately within the XML doc and then write the logic in ActionScript to create the new line for the elements you want.

          TS
          • 2. Re: \n parameter is not working
            manofspirit Level 1
            Thanks for d help buddy
            iM a designer and a i have very pathetic skills in programming like AS etc
            Can u plz explain your method of formatting data along with a working code?
            waiting and once again thanks for d help :)
            • 3. Re: \n parameter is not working
              VarioPegged Level 2
              No problem. Before I help out with some code, can you give me an idea of the context in which you're using the data. For example, I imagine a portion of the XML file could look something like this:
              ...
              <drawApps>
              <app>CorelDraw</app>
              <app>Illustrator</app>
              ...
              </drawApps>
              ...

              TS
              • 4. Re: \n parameter is not working
                manofspirit Level 1
                my xml file`s structure iz following
                <servicestart>
                <category>Design</category>
                <imagelink>images/des.jpg</imagelink>
                <tech>Photoshop\nCorelDraw\nIllustrator</tech>
                </servicestart>

                2 different "Text" Components [as i changed TextArea to Text] are caputring all above 2 fields
                Service Name
                Technologies

                Thanks :)
                • 5. Re: \n parameter is not working
                  manofspirit Level 1
                  Bundle of Thanks Buddy for the "&#xA;" as it works perfect
                  can you plz tell me where i get the information of these formating stuff [similar to &#xA;] from?

                  Why AS based way of \n is best? does AS based method works fast or something else?

                  Waiting for your favourable Reply
                  • 6. Re: \n parameter is not working
                    VarioPegged Level 2
                    You can find info on special characters at xml.org and unicode.org. Do a search for 'xml and html characters'. An example would be for the copyright symbol... the Unicode code is 00A9, so within an XML element you'd write &#00A9;

                    As far as using AS to add the newline... it will give you greater control if the XML elements are represented as separate values in the database field (of course assuming the XML is dynamically assembled during a service call). However, using your approach of directly embedding the newline character in your XML data would be faster, especially if the data is only going to be used by you for your specific application.

                    Here's a sample of how it could be handled if the XML data is dynamically assembled with the following format and returned in e4x resultFormat from the service call:

                    <servicestart>
                    <category>Design</category>
                    <imagelink>images/des.jpg</imagelink>
                    <tech>
                    <app>Photoshop</app>
                    <app>CorelDraw</app>
                    <app>Illustrator</app>
                    </tech>
                    </servicestart>

                    function handleResultEvent(event:ResultEvent):void
                    {
                    var apps:XMLList = event.result.tech.app;
                    var tmpStr:String = "";

                    if (apps.length() > 1)
                    {
                    for (var a:int = 0; a < apps.length() - 1; a++)
                    {
                    tmpStr += apps[a] + "\n";
                    }
                    tmpStr += apps[apps.length() - 1];
                    }
                    else
                    {
                    tmpStr += apps[0];
                    }

                    Technologies.text = tmpStr;
                    }

                    You can see how you have greater control over what you want to do with the data. If you're the only one who will ever use this data and only for your specific application, then the AS route is probably overkill, but it may come in handy to know how to do it.

                    TS
                    • 7. Re: \n parameter is not working
                      manofspirit Level 1
                      Thanks...:)
                      If iM not wrong XMLList is an Array and you wrote a for loop for creating new line...
                      Thanks, this code dznt only help me to use \n but I also got knowledge about XMLList and the way of using for loop in Flex...
                      I have the basic concepts of Programming Techniques [C++] but I havenot a practical experience, so I face difficulty to write a new code from myself, But my little knowledge help me to understand the code and use it in future...
                      You are simply Awesome
                      iM sure you ll help me in future problems as well
                      have a nice time