Flash textarea alignment and symbols

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sumaiya
    New Member
    • Apr 2007
    • 43

    Flash textarea alignment and symbols

    i have a dynamic textbox displaying data from a php webpage which is connected to a mysql table. Now the problem i am facing is as follows:

    1 - I cannot display symbols like & % ' etc flash just ignores the data after these symbols eg data=H & M flash displays = H.

    I know why it exepts & but i need to get around the problem

    2 - flash is displaying multiple line breaks Eg

    Case 1:
    Data = my name is sumaiya

    Case 2:
    data = my name
    is sumaiya

    In case1 flash is fine but in case2 it displays a line break whn there is no <br>++. I neeeed to get around this problem..... Please Help!!
  • xNephilimx
    Recognized Expert New Member
    • Jun 2007
    • 213

    #2
    Hi, sumaya.
    I reccomend you to use PHP to output an XML with the DB results, as Flash XML halding capabilities are awesome. So the you use PHP to read the XML (php) file.
    Anyway, you'll still have the same problem, and that is, problems with special characters. Let's say you have an XML tag <data> that will contain some text data loaded from the DB, first you need to put any content in the data between a CDATA block, a CDATA block is written like this, the opening tag is <![CDATA[ and the closing tag is ]]>, so it will read as follows:

    <data><![CDATA[The content loaded from the db here]]></data>
    The CDATA (character data) blocks allows special characters to be written inside the tag.

    Now you need php to conver any special chars to the HTML special chars form, you can do it by passing the content returned from the CB through htmlspecialchar s method or the htmlentities method, being the last one more strict, as it will conver almost any non utf-8 character to html special character notation (like an & is written &amp;).
    Anyway, Flash's html handling capability is outstandingly poor. And will probably not read any special char, and the reason is because it will transform it again, converting this &amp; to this: &amp&amp; making it totally unreadable. There's a solution, and that is to filter those special chars and re-construct them in ActionScript, the thing is, I'm not at home today and I'll be off for the weekend. But as soon as I get home I'll send you the function to do that, its really simple anyway. but it took me sooo long to realize what went wrong and coming up with this function.

    Best regards,
    The_Nephilim

    Originally posted by sumaiya
    i have a dynamic textbox displaying data from a php webpage which is connected to a mysql table. Now the problem i am facing is as follows:

    1 - I cannot display symbols like & % ' etc flash just ignores the data after these symbols eg data=H & M flash displays = H.

    I know why it exepts & but i need to get around the problem

    2 - flash is displaying multiple line breaks Eg

    Case 1:
    Data = my name is sumaiya

    Case 2:
    data = my name
    is sumaiya

    In case1 flash is fine but in case2 it displays a line break whn there is no <br>++. I neeeed to get around this problem..... Please Help!!

    Comment

    • sumaiya
      New Member
      • Apr 2007
      • 43

      #3
      Thanks for the answer I will work on that.

      But can you please explain with examples, cuz i know my PHP/mysql but xml actionscript are a lil blurred in my head.

      Comment

      • xNephilimx
        Recognized Expert New Member
        • Jun 2007
        • 213

        #4
        Yes, as soon as I get home I'll write you a full example, and a demo application so you can explore it. Putting special attention to XML and ActionScript.

        Well, gotta go.
        See you.

        Best regards,
        The_Nephilim

        Originally posted by sumaiya
        Thanks for the answer I will work on that.

        But can you please explain with examples, cuz i know my PHP/mysql but xml actionscript are a lil blurred in my head.

        Comment

        • xNephilimx
          Recognized Expert New Member
          • Jun 2007
          • 213

          #5
          Hi! I'm back!
          Well, let's start by refreshing you simple XML.

          A rule that you always must respect with XML files is that the file must only contain only one root element, that is like the HTML tag in an XHTML file. Making multiple root tags will lead you to errors and not being able to parse the file.

          Another thing that you shoud use is the xml declaration, with the version and encoding, that is the
          <?xml version="1.0" encoding="uft-8"?>
          I'm using utf-8 asi it's the most common, but it can be any encoding to suit your language (In my case sometimes I use iso-8859-1 as it's the latin 1 character set, it allows latin characters)
          When generating this declaration with php, youll encounter a problem, you will need to echo it out, because the <? tag will confuse php.
          Let's say you have a db for news, then your news table may have the following rows news_title, news_author, news_text, news_date, or similar.
          so the XML you want to output can be like this, let's make it output two articles:

          [CODE=xml]
          <?xml version="1.0" encoding="utf-8"?>
          <news>
          <article id="1">
          <title>Article' s 1 Title</title>
          <date>16-9-2007 15:04:49</date>
          <text><![CDATA[Output the article #1 here. Flash will respect line breaks but will treat the as paragraphs. If you want a line break use a br tag but don't output any line break.]]></text>
          <auhor>The_Neph ilim</author>
          </article>
          <article id="2">
          <title>Article' s 2 Title</title>
          <date>16-9-2007 15:04:49</date>
          <text><![CDATA[Output the article #1 here. Let's try a <a href="http://www.google.com" >link</a> now.]]></text>
          <auhor>The_Neph ilim</author>
          </article>
          </news>
          [/CODE]

          You see it's pretty easy. It's like a hierarchy of the data. The tags can be anything you like. And you can see there's only one root element, the <news> element. Then there are as many article elements a articles you have in the DB, each one containing the different element's that compose the article, the title, date, text and author.

          To output this with php it's easy, I know you already came up with a way to do it, but there's one more thing, you got to send a header telling flash that this is a real xml document. Easy, like this:
          header("Content-type: application/xml");
          (yes it's no longer text/xml)

          So the php file can be like this:
          [PHP]
          <?php

          $link = mysql_connect(" localhost","use r","password ");
          mysql_select_db ("your_db");

          $sql = "SELECT * FROM news ORDER BY news_id ASC";
          $result = mysql_query($sq l) or die(mysql_error ());

          header("Content-type: application/xml");

          echo '<?xml version="1.0" encoding="iso-8859-1"?>'."\n";
          ?>
          <news>
          <?php
          while($row = mysql_fetch_arr ay($result)) :
          ?>
          <article id="<?=$row['news_id']?>">
          <title><?=$ro w['news_title']?></title>
          <date>8/6/2007</date>
          <text><![CDATA[<?=$row['news_text']?>]]></text>
          <author>$row['news_author']?></author>
          </article>
          <?php
          endwhile;
          ?>
          </news>
          [/PHP]

          Now comes the Flash part. I'll refresh your memory first for XML parsing in flash

          [CODE=actionscri pt]
          var home:MovieClip = this; // this will make sure the home will always be the current _root and not the bottom-most root

          var xml:XML = new XML();
          xml.ignoreWhite = true;
          xml.onLoad = loadNews;
          xml.load("news. php?d=" + new Date().getTime( ));
          // the new Date().getTime( ) part is only to not let the php(xml) file get cached

          function loadNews() {
          var nodes:Array = xml.firstChild. childNodes;
          //now the nodes array will contain all the article elements with all of it's subelements

          for (i = 0; i < nodes.length; i++)
          {
          //let's say you want a button to be dinamicaly loaded for each article
          var b:MovieClip = home.attachMovi e("btn","b"+i,i );
          b._x = 10; //the 10 here
          b._y = b._height * i + 10; //and here, are the offset left and top respectively

          //new let's s create custom properties for each button that will contain the corresponding title, text, etc. of each article.
          b.title = nodes[i].firstChild.fir stChild.nodeVal ue;
          b.date = nodes[i].childNodes[1].firstChild;
          b.txt = nodes[i].childNodes[2].firstChild;
          b.onRelease = showNews;//this is what will happen when the user clicks on a button
          b.bText.text = b.title; //the caption of the button will read the title of the article
          }
          }

          function showNews(){
          //here we use the recently created proeprties to set the corresponding article
          home.newsPanel. title.text = this.titulo;
          home.newsPanel. date.text = this.fecha;
          home.newsPanel. txt.htmlText = rebuildHTML(thi s.txt.toString( )); /*and here comes the tricky part.
          Rebuilding all html tags and special characters so all will be properly displayed in Flash.
          */
          }

          //The most important function so far
          function rebuildHTML(the Text:String):St ring {
          var tempText:String = theText;
          var chunks:Array = new Array();

          //I believe it's pretty straight forward, self-explanatory.
          //Splitting the string for the troublesome characters and replacing them (joining) for the ones that shoud really be there. Then, simply returning the corrected string
          chunks = tempText.split( "&amp; lt;");//sorry for the space here
          tempText = chunks.join("<" );
          chunks = tempText.split( "&amp; gt;");//and here
          tempText = chunks.join(">" );
          chunks = tempText.split( "&amp; amp;");//and here
          tempText = chunks.join("&" );

          chunks = tempText.split( "href=&amp; quot;");//and here
          tempText = chunks.join("hr ef=\"");
          chunks = tempText.split( "&amp; quot;>");//and here
          tempText = chunks.join("\" >");
          return tempText;
          }
          //the spaces where only because this editor for some reason wasn't displaying correnctly the code. Delete the spaces between the &amp; lt; and the others.
          [/CODE]

          As you can see, it may seem a little far fetched, anyway it's really easy. I hope this solves the problem and point you to the right direction when it comes to handle db results with flash and php... xml is underestimated, but you got to take advatages of it's capabilities. Once you get used to it, you'll see that it is really the best way to do stuff like this, gives you more control above the whole funcionality and workflow of your application.

          Well, try it and let me know how you are doing!

          Best regards!
          The_Nephilim

          Originally posted by sumaiya
          Thanks for the answer I will work on that.

          But can you please explain with examples, cuz i know my PHP/mysql but xml actionscript are a lil blurred in my head.

          Comment

          • sumaiya
            New Member
            • Apr 2007
            • 43

            #6
            thanks for your reply.... it would have taken time. I am big time basic actionscript and hve nvr actually used XML but i know that it is easy.

            I will work on your solution and ask you if i have further doubts.

            Comment

            • xNephilimx
              Recognized Expert New Member
              • Jun 2007
              • 213

              #7
              You're welcome!
              Keep practicing, as XML will save u a lot of headaches in the furure.

              And any question you may have, don't hesitate to question.

              Best regards,
              The_Nephilim

              Originally posted by sumaiya
              thanks for your reply.... it would have taken time. I am big time basic actionscript and hve nvr actually used XML but i know that it is easy.

              I will work on your solution and ask you if i have further doubts.

              Comment

              • sumaiya
                New Member
                • Apr 2007
                • 43

                #8
                I worked on your example but I m confused how m i going to get the answer:

                The MYSQL
                i build mysql table news

                The PHP
                my php file news.php (exactly what you said)
                <?php

                $link = mysql_connect(" localhost","roo t","");
                mysql_select_db ("work");

                $sql = "SELECT * FROM news ORDER BY news_id ASC";
                $result = mysql_query($sq l) or die(mysql_error ());

                header("Content-type: application/xml");

                echo '<?xml version="1.0" encoding="iso-8859-1"?>'."\n";
                ?>
                <news>
                <?php
                while($row = mysql_fetch_arr ay($result)) :
                ?>
                <article id="<?=$row['news_id']?>">
                <title><?=$ro w['news_title']?></title>
                <date>8/6/2007</date>
                <text><![CDATA[<?=$row['news_text']?>]]></text>
                <author>$row['news_author']?></author>
                </article>
                <?php
                endwhile;
                ?>
                </news>
                /* shouldnt this part be in the echo statement as well?? */

                The Flash
                I opened a new flash file, made a movieclip and wrote your actionscript but now how do i get the data.

                I know how do get the dynamic data from the php file n dynamic text fields ++ but .. here im confused

                Comment

                • sumaiya
                  New Member
                  • Apr 2007
                  • 43

                  #9
                  Now i have got the XML flash php thngy finally working...... but i now i hve another problem.

                  Now I can display symbols and characters by xml <![CDATA

                  BUT

                  now i cant use html formatting like links, bold, italic......... ... which is like a necessity. Now i want to display the characters as well as html formatting.

                  How do i do thtat

                  Comment

                  • xNephilimx
                    Recognized Expert New Member
                    • Jun 2007
                    • 213

                    #10
                    Hi, sumaiya! Sorry for taking so long to reply.
                    Glad you got the PHP part working, and talking about that, it's not necesarry to echo the </news>.

                    About the HTML, notice that the tag <i> will particularly tend to fail, so try not tu use it, but there's no problem with bold and link tags, AFAIK.
                    With the function I posted before (the rebuildHTML something...) the HTML should be working.

                    Please, post your actionscript code (all of it) so I can take a look and see where s it failing.

                    Best regards,
                    The_Nephilim

                    Originally posted by sumaiya
                    Now i have got the XML flash php thngy finally working...... but i now i hve another problem.

                    Now I can display symbols and characters by xml <![CDATA

                    BUT

                    now i cant use html formatting like links, bold, italic......... ... which is like a necessity. Now i want to display the characters as well as html formatting.

                    How do i do thtat

                    Comment

                    • sumaiya
                      New Member
                      • Apr 2007
                      • 43

                      #11
                      Todayyyyyyyy i actually got it working ..........

                      thank you sooo much this project will my first complete interactive flash project with a CMS n all. Do check my website rulerofdubai.co m by december thts whn v r suppose to launch it (deadline !!!) .... Inshalla i ll be done with it by then.

                      Thanks again, i ll post your help on my personal website as well hope you dont mind.

                      Comment

                      • xNephilimx
                        Recognized Expert New Member
                        • Jun 2007
                        • 213

                        #12
                        Hi, sumaiya!
                        I'm really glad you got it working!
                        I'll be checking your site then!

                        Best regards!!
                        The_Nephilim

                        PD: I don't mind if you name me on your site. In fact, I'll be flatterd. ^_^

                        Originally posted by sumaiya
                        Todayyyyyyyy i actually got it working ..........

                        thank you sooo much this project will my first complete interactive flash project with a CMS n all. Do check my website rulerofdubai.co m by december thts whn v r suppose to launch it (deadline !!!) .... Inshalla i ll be done with it by then.

                        Thanks again, i ll post your help on my personal website as well hope you dont mind.

                        Comment

                        • sumaiya
                          New Member
                          • Apr 2007
                          • 43

                          #13
                          The Link: http://www.phpjavascri pt.com/script.php?scri ptid=95

                          Comment

                          • xNephilimx
                            Recognized Expert New Member
                            • Jun 2007
                            • 213

                            #14
                            Awesome!
                            And thanks for the link XD
                            When I finish my site (at least the blog part) I'll put a link to it and your site.

                            Hey, I was just wandering... I have a problem with Ajax+PHP+MySQL, in this post: http://www.thescripts. com/forum/thread726829.ht ml
                            Check it out and see if you have any clues. I'd really appreciate it. Sice it appears you are a PHP girl ^_^
                            The problem is kind of like this one of yours, but with other languages, LOL

                            Best regards!
                            The_Nephilim

                            Originally posted by sumaiya
                            The Link: http://www.phpjavascri pt.com/script.php?scri ptid=95

                            Comment

                            • sumaiya
                              New Member
                              • Apr 2007
                              • 43

                              #15
                              Sorry couldnt reply earlier didnt check thescripts.com for a long time. But it seems you have solved the problem.

                              Thanks for your message.

                              I have a doubt regarding the function rebuildHTML(). It works fine but I have noticed a lot of html formatting is not supported like <font size="14">. <img src="cat.jpg"> works fine but <img src="cat.jpg" align="right"> or <img src="cat.jpg" /> does not work.

                              How do i overcome this issue i tried adding to the function like
                              chunks = tempText.split( "alt=&quot; ");
                              tempText = chunks.join("al t=\"");
                              chunks = tempText.split( "align=&quot;") ;
                              tempText = chunks.join("al ign=\"");

                              But it didnt help.

                              Comment

                              Working...