11 Replies Latest reply on Jan 30, 2007 11:49 AM by Peter Lorent

    String Manipulation

    exPluda? Level 1
      Hello,

      I need some help here doing a string manipulation,

      I have on php output like this

      month1=January&. fair1 / 18 to 22 . fair2 25 to 29
      &month2=April&. fair11 to 4 . fair2 28 to 4
      &&n=5

      I need to make flash read how many fairs there are inside each month, so I can create my buttons.

      Any ideia?

      I'm triing this flash code,

      var lv:LoadVars = new LoadVars();
      lv.load("php/listar_news.php");
      lv.onLoad = function(sucesso) {
      if (sucesso) {
      for (knews=1; knews<this.n; knews++) {
      var noticias:String = this["mes"+knews];
      for (kn=0; kn<noticias.length; kn++) {
      noticia = noticias[kn].split("\n");
      getURL("javascript:alert('"+noticias[0]+"')");
      }
      }
      }
      };

      Thanks a lot,

      Pluda
        • 1. Re: String Manipulation
          Peter Lorent Level 2
          That would be much easier to do with an xml file Pluda.
          • 2. Re: String Manipulation
            exPluda? Level 1
            Thanks for reply LuigiL :-)

            ok, I made php output xml, but I still don't get how this works, I don't usually use xml, sorry

            I got this outputed by php

            <noticias>
            <mes label="January">
            <noticia label="Intergift 2007 | 18 to 22 Madrid">
            </noticia>
            <noticia label="Planete du meuble 2007 | 25 to 29 Paris">
            </noticia>
            <noticia label="Maison et Objet 2007 | 26 to 30 Paris">
            </noticia>
            </mes>
            <mes label="February">
            <noticia label="Interdecoração 2007 |1 to 4 Porto - Exponor, International fair Porto">
            </noticia>
            <noticia label="ExportHome 2007 | 28 to 4 - Exponor, Porto">
            </noticia>
            </mes>
            <mes label="March">
            <noticia label="FIM Feria internacional del Meuble Madrid 2007 | 11 to 15">
            </noticia>
            </mes>
            <mes label="September">
            <noticia label="Ceranor 2007 | 6 to10 - Exponor, Porto">
            </noticia>
            <noticia label="Maison et Objet 2007 | 7 to 11 Paris">
            </noticia>
            <noticia label="Intergift 2007 | 13 to 17 Madrid">
            </noticia>
            <noticia label="FIM - HABITAT 2007 | 24 to 29 Valência">
            </noticia>
            </mes>
            </noticias>

            Now I need to create one movieclip for each month ant inside of it one textfield for each fair, I'm trying with this as

            xml_menu = new XML();
            xml_menu.ignoreWhite = true;
            xml_menu.load("php/listar_news.php");
            xml_menu.onLoad = function(sucesso) {
            if (sucesso) {
            mes = this.firstChild;
            var noticias:Array = mes.childNodes;
            for (var i = 0; i<=noticias.length; i++) {
            //getURL("javascript:alert('"+noticias +"')");
            _root.createEmptyMovieClip("mc_not"+i, i);
            _root["mc_not"+i]._x = 10;
            _root["mc_not"+i]._y = 10;
            _root["mc_not"+i].createTextField("not"+i, this+i, 10, 10, 200, 22);
            _root["mc_not"+i]["not"+i].text = noticias
            ;
            if (i == 1) {
            _root["mc_not"+i]._y = 10;
            } else {
            _root["mc_not"+i]._y = _root["mc_not"+(i-1)]._y+_root["mc_not"+(i-1)]._height+5;
            }
            }
            System.useCodepage = true;
            }
            };


            this creates my movieclips, but I can't access to the node variables...

            Can you please have a look?

            Thanks a lot
            • 3. Re: String Manipulation
              Peter Lorent Level 2
              Pluda, use the attach code option to post your code (bracket i bracket is seen as italic by this forum).

              Are you coding this on the timeline? Would you be comfortable with using classes to parse the xml?
              (have to go out now for an hour or so, but I can have a look later today).
              • 4. Re: String Manipulation
                exPluda? Level 1
                ok, LuigiL, I'm using the code otion now,

                the php output

                • 5. Re: String Manipulation
                  Peter Lorent Level 2
                  See the attached code Pluda.

                  • 6. Re: String Manipulation
                    exPluda? Level 1
                    hello again, well it seems xml is indeed the way of doing this :-9

                    but how do I get the "childs" of each month?

                    loking at my php output we can see that on January per example we have 3 diferent fairs, 1 in spain and 2 in paris

                    what I need is to be able of making flash read that content and organize it has a calendar

                    january
                    > 1st fair
                    > 2nd fair
                    > 3rd fair

                    february

                    Thanks a ton!
                    • 7. Re: String Manipulation
                      Peter Lorent Level 2
                      Then you need another loop that gets every childNode of the 'mes' nodes. See attached script.

                      • 8. Re: String Manipulation
                        exPluda? Level 1
                        yep, that surelly give me the records, thanks LuigiL.

                        This is being much complicated that I was thinking it would be, I'm facing problems managing this xml content, but I will study your code.

                        Thanks
                        • 9. Re: String Manipulation
                          Peter Lorent Level 2
                          Once you get the hang of it, you won't use LoadVars anymore....
                          Attached a snippet so you can see how the get data from a xml file.

                          • 10. Re: String Manipulation
                            exPluda? Level 1
                            Yep, I'm liking it!

                            My problem is I can't make what I want and need
                            I now can access to the xml contents, but I don't know why, I can't create my textfields correctly

                            basically what i want is simple, but it is not working, and I'm being without ideas here :-(


                            I can create the movieclips and textfields inside of them with text = month, but I'm not able to create inside of each month the correspondent fair he has, but I guess its a question of many hours seating here in front of my mac

                            Thanks for your efort and example, I already copy pasted him and I'm going to test it.
                            • 11. Re: String Manipulation
                              Peter Lorent Level 2
                              Tip: chop your code up in smaller pieces. Load the xml, save it in an array. In the onLoad handler call a function that builds the clips.