Skip navigation
ozkan0588
Currently Being Moderated

How to take information in this xml?

Aug 3, 2012 5:36 AM

Tags: #xml #as3.0 #ac3 #actionscript3

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

 
Replies
  • Currently Being Moderated
    Aug 3, 2012 6:06 AM   in reply to ozkan0588

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 3, 2012 6:15 AM   in reply to ozkan0588

    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/WS5b3ccc516d4fbf351e63e3d118a9b902 04-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/WS5b3ccc516d4fbf351e63e3d118a9b902 04-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/fla sh/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/fla sh/text/TextField.html#TextField()

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 3, 2012 8:47 AM   in reply to ozkan0588

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 7, 2012 8:35 AM   in reply to ozkan0588

    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/fla sh/utils/Timer.html?filter_flash=cs5&filter_flashplayer=10.2&filter_ai r=2.6

     

    examples:

    http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b902 04-7f0f.html#WS5b3ccc516d4fbf351e63e3d118a9b90204-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!

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 29, 2012 6:35 AM   in reply to ozkan0588

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 30, 2012 6:32 AM   in reply to ozkan0588

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 5, 2012 6:42 AM   in reply to ozkan0588

    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/fla sh/display/Graphics.html

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points