5 Replies Latest reply on Oct 15, 2009 9:41 AM by kglad

    Trim text from XML...(how to add a read more link)

    TarunaR

      I am stuck...I want to have a read more link after 30th word in each paragraph loading from the xml file...Any help?

       

      I do not even know how to begin with it...I have 5 movie clips with instance name mc1,mc2,mc3,mc4,mc5. When I rollover they load the content from XML in the toolTipMC.

       

      Code:-


      var x:XML = new XML();

      x.ignoreWhite = true;

      var images:Array = new Array();
      var titles:Array = new Array();
      var details:Array = new Array();
      var urls:Array = new Array();

       

      x.onLoad = function(success) {
          var locs:Array = this.firstChild.childNodes;
          for(j=0;j<locs.length;j++) {
              images["mc"+(j+1)] = locs[j].attributes.image;
              titles["mc"+(j+1)] = locs[j].attributes.title;
              details["mc"+(j+1)] = locs[j].attributes.detail;
              urls["mc"+(j+1)] = locs[j].attributes.url;
             
          }
         
      }

       

       

      x.load("data.xml");


                     

              myBtn.onRollOver = function() {

                     
                      toolTipMC.img.imgHolder.loadMovie(images[this._name]);
                      toolTipMC.tip.text = titles[this._name];
                      toolTipMC.detail.text = details[this._name];           
                 
              };
             

        • 1. Re: Trim text from XML...(how to add a read more link)
          kglad Adobe Community Professional & MVP

          if by 30th word, you can check for 29 spaces.  that should be close.

           

          but generally, you fill a textfield and then back it up enough to find a space or punctuation mark and then add your ellipsis and more link.

          • 2. Re: Trim text from XML...(how to add a read more link)
            TarunaR Level 1

            Your reply is appreciated

             

            However i am really not sure how to begin with? Like after loading the text, How should I check for 29 spaces, and how should i add "read more" at the end linked to some page in the website, now this link should be an attribute from the element of the XML (example of XML is below)? (This trim is very comman in other languages. But how to built one in Action Script?)

             

            XML:-

            <mcs>

            <mc image="images/mc1.jpg" title="MC1"  detail="A fantastic Movie Clip 1, lol !! dummy text dummy text dummy text dummy text dummy text dummy text dummy text dummy text dummy text dummy text dummy text dummy text dummy text dummy text dummy text dummy text..." url="html/page-one.html"></mc>

            <mc image="images/mc2.jpg" title="MC2"  detail="A fantastic Movie Clip 2, lol !! dummy text dummy text dummy text dummy text dummy text dummy text dummy text dummy text dummy text dummy text dummy text dummy text dummy text dummy text dummy text dummy text..." url="html/page-two.html"></mc>

            </mcs>

            • 3. Re: Trim text from XML...(how to add a read more link)
              kglad Adobe Community Professional & MVP

              i really don't think you should be using that but, the following will return a substring that includes 29 spaces and about 30 "words":

               

              function textto29F(s:String):String{

              var spaceNum:Number=0;

              for(var i=0;i<s.length;i++){

              if(s.charAt(i)==" "){

              spaceNum++;

              if(spaceNum==30){

              return s.substr(0,i);

              }

              }

              }

              // s contains less than 29 spaces

              return s;

              }

              • 4. Re: Trim text from XML...(how to add a read more link)
                TarunaR Level 1

                so i tried doing something with your code. I stored the details coming from xml in the variable s. Not sure what i am doing, how to proceed....

                 

                myBtn.onRollOver = function() {

                 

                            if (miniMap._visible) {
                                this.useHandCursor = false;

                 

                                toolTipMC.img.imgHolder.loadMovie(images[this._name]);
                                toolTipMC.tip.text = titles[this._name];
                                s = details[this._name];
                                toolTipMC._visible = true;

                 

                                this._alpha = 40;
                               
                                var spaceNum:Number=0;
                                var spaceTen = s.letterAt(150);

                 

                                for (var i = 0; i<s.length; i++) {
                                   
                                    if (s.charAt(i) == " ") {

                 

                                        spaceNum++;

                 

                                        if (spaceNum == 10) {

                 

                                            //return s.substr(0, i);
                                           
                                            toolTipMC.detail.text = s.split(spaceTen);
                                            //s;
                                            s.appendText(" Read More..");

                 

                                        }

                 

                                    }

                 

                                }

                 


                            }

                • 5. Re: Trim text from XML...(how to add a read more link)
                  kglad Adobe Community Professional & MVP

                  you can use the following but your Read More is not a link:

                   

                   


                  myBtn.onRollOver = function() {

                   

                              if (miniMap._visible) {
                                  this.useHandCursor = false;

                   

                                  toolTipMC.img.imgHolder.loadMovie(images[this._name]);
                                  toolTipMC.tip.text = titles[this._name];
                                  s = details[this._name];
                                  toolTipMC._visible = true;

                   

                                  this._alpha = 40;

                  toolTipMC.detail.text = textto29F(s)+" Read More...";


                             }

                   


                              }