13 Replies Latest reply: Sep 5, 2012 6:42 AM by sinious RSS

    How to take information in this xml?

    ozkan0588 Community Member

      I want take this information node by node. And if tag name is BolumAdi a movieclip run.   And background be grey.

      <?xml version="1.0" encoding="UTF-8"?>medipol.JPG

      <data>

          <servis>

              <BolumAdi>bolum 1</BolumAdi>

              <doktor>

                  <DoktorAdi>Medipol 1 doktor 1</DoktorAdi>

                  <DoktorAdi>Medipol 1 doktor 2</DoktorAdi>

                  <DoktorAdi>Medipol 1 doktor 3</DoktorAdi>

                  <DoktorAdi>Medipol 1 doktor 4</DoktorAdi>

              </doktor>

          </servis>

       

          <servis>

              <BolumAdi>bolum a</BolumAdi>

              <doktor>

                  <DoktorAdi>Medipol 1 doktor 1</DoktorAdi>

                  <DoktorAdi>Medipol 1 doktor 2</DoktorAdi>

                  <DoktorAdi>Medipol 1 doktor 3</DoktorAdi>

                  <DoktorAdi>Medipol 1 doktor 4</DoktorAdi>

              </doktor>

          </servis>

       

       

          <servis>

              <BolumAdi>bolum s</BolumAdi>

              <doktor>

                  <DoktorAdi>Medipol 1 doktor 1</DoktorAdi>

                  <DoktorAdi>Medipol 1 doktor 2</DoktorAdi>

                  <DoktorAdi>Medipol 1 doktor 3</DoktorAdi>

                  <DoktorAdi>Medipol 1 doktor 4</DoktorAdi>

              </doktor>

          </servis>

       

          <servis>

              <BolumAdi>bolum d</BolumAdi>

              <doktor>

                  <DoktorAdi>Medipol 1 doktor 1</DoktorAdi>

                  <DoktorAdi>Medipol 1 doktor 2</DoktorAdi>

                  <DoktorAdi>Medipol 1 doktor 3</DoktorAdi>

                  <DoktorAdi>Medipol 1 doktor 4</DoktorAdi>

              </doktor>

          </servis>

       

          <servis>

              <BolumAdi>bolum 2</BolumAdi>

              <doktor>

                  <DoktorAdi>Medipol 2 doktor 1</DoktorAdi>

                  <DoktorAdi>Medipol 2 doktor 2</DoktorAdi>

                  <DoktorAdi>Medipol 2 doktor 3</DoktorAdi>

              </doktor>

          </servis>

       

          <servis>

              <BolumAdi>bolum 3</BolumAdi>

              <doktor>

                  <DoktorAdi>Medipol 3 doktor 1</DoktorAdi>

              </doktor>

          </servis>

       

          <servis>

              <BolumAdi>bolum 4</BolumAdi>

              <doktor>

                  <DoktorAdi>Medipol 4 doktor 1</DoktorAdi>

                  <DoktorAdi>Medipol 4 doktor 2</DoktorAdi>

                  <DoktorAdi>Medipol 4 doktor 3</DoktorAdi>

                  <DoktorAdi>Medipol 4 doktor 4</DoktorAdi>

              </doktor>

          </servis>

       

          <servis>

              <BolumAdi>bolum 5</BolumAdi>

              <doktor>

                  <DoktorAdi>Medipol 5 doktor 1</DoktorAdi>

                  <DoktorAdi>Medipol 5 doktor 2</DoktorAdi>

              </doktor>

          </servis>

      </data>

       

      Message was edited by: ozkan0588

        • 1. Re: How to take information in this xml?
          Ned Murphy MVP

          What part of processing the xml do you not understand?  What code do you have so far that is not working for you?

           

          Based on the apparent structure of the data and the image you provide, you will want to parse the data based on processing each servis node entirely one at a time.  For each servis node you first want to extract the BolumAdi node, followed by extracting the DoktorAdi nodes within the doktor node.

          • 2. Re: How to take information in this xml?
            sinious MVP

            First step is to import the XML, you can use the URLLoader class to do that, set for text. An example of URLLoader reading XML:

             

            http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e6a.html

             

            After you load the XML you need to traverse it. Here's an example of accessing elements in the XML you just loaded:

             

            http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e6b.html

             

            Checking the length() method of each node is a good way to determine existence so that can help you with drawing gray boxes and spawning a MovieClip.

             

            I see your picture on how you expect it to look but are you being literal when you show that picture? If so you need to code it so it stacks the results like you have it and it probably won't look at neat and clean unless you have exactly the same number of rows and columns like in that picture (11 rows, 3 columns).

             

            To make the names with the boxes around them you can either switch the design to a datagrid component (I'm assuming you don't want to) or just draw it like you did using sprites and the graphics class with drawRect:

             

            http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics. html#drawRect()

             

            There's an example there on how to draw a rectangle and color it. You'd just be applying your lineStyle as like a 1 pixel wide black line. Aside that it's just inserting a TextField inside it:

             

            http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.ht ml#TextField()

            • 3. Re: How to take information in this xml?
              ozkan0588 Community Member

              var fieldCount:XML = XML(loader.data);

              var bolumLength:int = xml.servis.BolumAdi.length();

              var i:int = 0;

              var doktorInfo:Array=new Array();

              var bolumInfo:Array=new Array();

               

              for (i; i < bolumLength; i++)

              {

                  if (i < 36)

                  {

                      var bolumler:String = xml.servis[i].BolumAdi;

                      bolumInfo.push(bolumler);

                      movies[i+1].alan1.text = bolumInfo;

                      addChild (movies[i]);

                     

               

               

                      var k:int = 0;

               

                      for (k; k<xml.servis[i].doktor.DoktorAdi.length() ; k++)

                      {

                         

                          var doktorlar:String = xml.servis[i].doktor.DoktorAdi[k].child(0);

                          doktorInfo.push(doktorlar)

                      }

               

                  }

                  else

                  {

                      trace("ikinci sayfaya artık");

                  }

              }

               

               

               

              I read xml another frame. I want parse xml and add array. the read . if tag name bolum adi make background grey,else white.

              • 5. Re: How to take information in this xml?
                sinious MVP

                Here's a quick re-write of your code, condensing it down as much as possible.

                 

                Obviously in your original you reference a lot of movieclips that are not in the library I see. It's up to you to hook up the bottom function which fires off when you click one of the clips with the blue background.

                 

                I re-wrote it to use loops instead of all the hard coded references. I don't know what references you actually wanted to keep around but I'm using the clips name to store the index of the XML element so that should be enough (0-36) so you can program it to load the correct movie. I can't tell you what movie is correct, only you know that.

                 

                Saved down to CS4, I don't know what you're working with:

                http://www.ertp.com/demo/medipolDoktor_rewrite_CS4.zip

                 

                I used the mc you had in the library. I'm assuming you wanted to use that.

                • 6. Re: How to take information in this xml?
                  ozkan0588 Community Member

                  thanks sinious. I have another questions. İf i want to add tween this code how to make this. And if info bigger than 36 , i want saw 37-72 in  second page in a timer.

                  • 7. Re: How to take information in this xml?
                    sinious MVP

                    You have to jump in somewhere and take over. You can see my code very simply adding in a bunch of your "mc" clips with a name in each of them. A good idea is to make a container (if I didn't, I don't recall) and add all the numbers added to that container. Then use a Timer and when the timer hits, remove all the numbers from the container and add in 37-72, etc. Here's a link to the Timer class with simple examples:

                     

                    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/Timer.html? filter_flash=cs5&filter_flashplayer=10.2&filter_air=2.6

                     

                    examples:

                    http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f0f.html#WS5b3cc c516d4fbf351e63e3d118a9b90204-7f07

                     

                    I put in some hard coded logic to display the first 36 items as well as which column and row (x and y position) the next item goes in. You'll need to adjust that code to be more flexible. For example to keep it running just how it does now you can just keep track of a starting position in the XML via a variable like _currentXMLIndex:int = 37;.. Then create a new XMLList that only contains the items you want and feed that into the loop that creates the numbers so it can still start at.

                     

                    Take what I've done already and experiment. It shouldn't be too hard to figure these things out and you won't get it right off the first try but that's how you grow as a coder. Feel free to post back any specific questions.

                     

                    If you're done please mark the thread answered and good luck!

                    • 8. Re: How to take information in this xml?
                      ozkan0588 Community Member

                      Hi Sinious, i try to make but i didn't make this project. I change xml index to 72.

                       

                      https://www.wetransfer.com/dl/vjG8sBN9/47563f65046c89b78dce97580eecc7024b4ec81b7885eb3d031 655625925127cafa474544ebbc45

                       

                      Can you help me?

                      • 9. Re: How to take information in this xml?
                        sinious MVP

                        I can only give you some tips.

                         

                        My first tip would be, you shouldn't be using Flash for this. This is something JavaScript could do extremely easily and is far more appropriate if this is going on the web. If it's being embedded in a presentation then that may be different but I would assume if it was you'd just create the table in the presentation itself, so I don't think it is.

                         

                        Your document only supports 66 as it was originally created. To increase it to 72 simply means you need more vertical document space, 2 more rows with 3 columns. You know the height of each row is 42 so you know you need to add 84px more height to your document.

                         

                        You have some shared object code I never understood what you were doing with but it still points to 66, so I guess that should be 72:

                         

                        var so:SharedObject = SharedObject.getLocal("Medipol");

                        so.data.Sayı;

                        var index:int = so.data.Sayı + 66;

                        so.data.Sayı = index;

                         

                        Lastly in the _createTextClip() function you can see hard-coded values. It is checking the "currentTextFieldIndex" and if it's past a certain point it knows to go to the next column. You will need to adjust those to suit. They should be checking instead for "< 23" and "< 45" to "< 25" and "< 49".

                         

                        You just need to update the hard-coded numbers in your document to match your needs. Again I stress if this is going on the web it's far better to do this in plain JavaScript/HTML so a device (phone/tablet) can see the infor and search engines can index it.

                        • 10. Re: How to take information in this xml?
                          ozkan0588 Community Member

                          I would like to do something else. Currently working as a field 66. If you have more information in the xml show on the second page. I tried to write a timer function, but I could not. For example, a screen renew 10 seconds. Send finished as the first page. If I do it'll take two days off. Need a lot of help, you see.

                          • 11. Re: How to take information in this xml?
                            sinious MVP

                            The help you need is in my above post. Saying someone else should do it because it would take you longer just points out you really need to learn to do things yourself. Come here for questions, not to get your projects completed for you.

                             

                            Your timer idea is a good idea to keep 66 spots and rotate them. Typically people would offer a < Previous and Next > button to go between pages but I realize that might get complicated for you. To implement your idea of changing pages, all you need to do is keep track of which XML element to start with. If you save a variable on which element to start with and only read elements beyond that it should work fine. You'll need to clear all your clips as well.

                             

                            Because I rapidly rewrote some of your old code I'll show you 2 simple bits but you need to do this for yourself.

                             

                            I didn't put your "mc" clips in a container so you'll need to iterate the display list looking for clips with "txt_bilgi-" in their name to remove. To clear out all existing clips so you can "re-create" them would be a function like this:

                             

                            function removeAllTextFields():void

                            {

                                for (var diIndex:int = 0; diIndex < this.numChildren; diIndex++)

                                {

                                    var obj:Object = getChildAt(diIndex);

                                    if (obj.name.toString().indexOf('txt_bilgi-') != -1)

                                    {

                                        trace("Found: " + obj.name);

                                        removeChild(MovieClip(obj));

                                    }

                                }

                            }

                             

                            Run that to get rid of the "mc" clips that are made. Next make a variable to keep track of your starting point in the XML.

                             

                            Second, where you loop through the XML with the "for (var k:int = 0; k < xml.servis[i].doktor.DoktorAdi.length(); k++)" is where you want to use the variable. Set the value of k to that number so it either starts at 0 or at another number down the XML so the loop will only iterate on the items you want.

                            • 12. Re: How to take information in this xml?
                              ozkan0588 Community Member

                              sinious i didn't do this. But i make another way.

                               

                              http://wtrns.fr/aRFsy4ImLZTNRw

                               

                              But i didn't make second page and another pages. How to i saw third page example?

                              • 13. Re: How to take information in this xml?
                                sinious MVP

                                I'm sorry but you'll either need to re-think how static and non-dynamic you're making this. Your approach should be to learn the DisplayObject's graphics class so you can learn to dynamically draw these clips and remove them at will. I've already pasted a line of code and told you how to change the offset you start at. With both of those tools you can make your clips with a TextField dynamically starting and ending at any position you like. There's also some code there to remove the clips before rebuilding them at a new offset. The rest is up to you to implement.

                                 

                                http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics. html