A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 28

Thread: Interactive Map - Need xml assistance

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Posts
    16

    Interactive Map - Need xml assistance

    I have an interactive state map, when you mouse over a county certain statistics are displayed.

    My client wants to be able to change the statistics. I understand that xml is probably the best way to do this but I have never done anything like this before. Is there a good tutorial or can someone walk me through how to do this?

    Thanks in advance!

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    in my footer is is a link called xml101.. this may help give a quick understand on how to load and parse the XML data..

    basically XML is nothing more a more organized way to bring data into your project then a regular .txt file.

    once you load and parse the XML data.. you still have to write code (AS) to handle the data, and do what you want done with it..

  3. #3
    Junior Member
    Join Date
    Jun 2009
    Posts
    16
    Thanks for the reply but I have no idea where to even start. How do I set up the info in my xml file?

  4. #4
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    Thats up to you.. there is no 'real' set way to set-up your XML outside of a few rules.

    thats what makes XML so powerful...its flexible..

    basically set tings up in an intuitive format/grouping..organizing associated data together

    example:

    PHP Code:
    <states>
        <
    state name="Alabama" color="FF0000">
            <
    desc>Some text here saying whatever</desc>
        </
    state>
        <
    state name="Arizona" color="CC00FF">
            <
    desc>Some text here saying whatever</desc>
        </
    state>

    </
    states
    and so on.. for each states..

    if you look.. I made a <states></states> node.. and inside those tags.. I grouped simialr data (<state></state> tags)...

    inside each <state> tag.. I put data associated with that state..

    the tag names are what you want them to be.. but you need to open & close them like an HTML tag..

    the above is a VALID XML layout (schema)

  5. #5
    Junior Member
    Join Date
    Jun 2009
    Posts
    16
    Ok, I think I'm starting to get it. I've attached a screen shot of the file I'm working on; when you hover over a county the information is displayed. How do I display the ages and pregnancy rate information in the xml file?

    Also do I need to list the counties in alphabetical order?

    Thanks again, this has been a huge help.
    Attached Images Attached Images

  6. #6
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    ok..so this is for counties? and not states?.

    either way the approach would be the same..

    1.) you need to have all those 'counties' be individual buttons/movieclips.
    2.) you would need an XML file that has all the data you want to display/add.. (what is it?, JUST ages and pregnancy info?)
    3.) you would need to load, then loop through this XML file and add the data to each clip (county) on the map...
    4.) while you are looping through the XML data and assigning the specific data to each clip...you can also assign rollOver/Out actions.. to display a pop-up or whatever and display the info.

    as for the XML file..

    you could do this:

    PHP Code:
    <counties>
        <
    county name="County1" age="24" rate="24.1" />
        <
    county name="County2" age="18" rate="106" />
        .....
    </
    counties
    when ypou put the data i-line that the above.. its called using an attribute, instead of a full 'node/element' to hold the data..

    the above is basically the same as this.. (but the above is a little easier and less text)

    PHP Code:
    <counties>
        <
    county>
            <
    name>county 1</name>
            <
    age>24</age>
            <
    rate>24.1</rate>
        </
    county>
        <
    county>
            <
    name>county 2</name>
            <
    age>18</age>
            <
    rate>106</rate>
        </
    county>
    </
    counties
    are are valid.. and will work..but if you data is simple..and doesnt need any special formatting the top approach is easier and less work.

  7. #7
    Junior Member
    Join Date
    Jun 2009
    Posts
    16
    Unfortunately the info has to be displayed a certain way, so I should use the second example?

  8. #8
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    what do you mean a certain way? you can do whatever you want with the data...

    the XML schema/layout comes into play if you have more than one piece of the data for the same thing.. looking at the image you linked to..

    will each county have the same breakdown for ages? 3 age categories?

    when you have the similar data for an item..it is best to group them together in a parent node/element.. this makes it EASIER in flash to loop through that specific node and grab only that data..

    example:
    PHP Code:
    <counties>
        <
    county name="county1">
            <
    ages>
            <
    age>20</age>
            <
    age>22</age>
            <
    age>24</age>
        </
    ages>
            <
    rates>
            <
    rate>12</rate>
            <
    rate>106</rate>
            <
    rate>48</rate>
        </
    rates>
        </
    county>
        <
    county name="county2">
            <
    ages>
            <
    age>20</age>
            <
    age>22</age>
            <
    age>24</age>
        </
    ages>
            <
    rates>
            <
    rate>12</rate>
            <
    rate>106</rate>
            <
    rate>48</rate>
        </
    rates>
        </
    county>
    </
    counties

    or maybe this type of layout would work best for you:

    PHP Code:
    <counties>
        <
    county name="county1">
            <
    statistics>
                    <
    data age="18" rate="24" />
                    <
    data age="20-24" rate="106" />
                    <
    data age="25+" rate="20" />
            </
    statistics>
        </
    county>
        <
    county name="county2">
            <
    statistics>
                    <
    data age="18" rate="33" />
                    <
    data age="20-24" rate="126" />
                    <
    data age="25+" rate="44" />
            </
    statistics>
        </
    county>
    </
    counties
    keep in mind XML is nothing more than an 'organized' text file.. its just a way to bring in data into your flash movie.. nothing more.. you still have to code things on the flash side to handle that data and display how & where you see fit.

  9. #9
    Junior Member
    Join Date
    Jun 2009
    Posts
    16
    As you hover each county that counties information is displayed. I just need to make sure that the information for each county displays consistently (like the screen shot shows)

    In answer to your question: will each county have the same breakdown for ages? 3 age categories? Yes.

  10. #10
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    consistently...?? as in all the time? or visible until you rollover a new 'county'?

    I suggest my last XML layout/schema then...

    I would also suggest you name each clip(county) the same as you use in the county name in the XML field..so you can easily target (find) the clip on the stage and assign data to it..

  11. #11
    Junior Member
    Join Date
    Jun 2009
    Posts
    16
    The format of the text needs to be the same for each county:
    Ages
    10-14
    15-17
    18-19

    Pregnancy Rates
    1.3
    29.7
    101.7

    If you'd like I can send you the .fla file but I won't be able to send it through the forum, it's over the size limit

  12. #12
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    I dont need the .fla (I dont wanna do the project for ya!) LOL

    Im just trying to help you understand so you can do whatever works best for you.

    so each age bracket/range is the same for EACH/EVERY county...

    and only the Prego. Rates change?

    if so then you dont need the age attribute in the XML file..

    basically you'll load the XML file..and pick (parse) out the data you need.. you will need to decide how & where you want to put this data.. will you have 3 separate text fields for the rates of each county? 1 text field that you just format with line spaces?..etc

    make sense?

  13. #13
    Junior Member
    Join Date
    Jun 2009
    Posts
    16
    That is correct, the age ranges are the same for each county only the prego rates will change. With that being said should my xml file look like this?:

    <counties>
    <county name="Adams">
    <statistics>
    <data rate="0.0" />
    <data rate="10.3" />
    <data rate="61.3" />
    </statistics>
    </county>

    Thanks again for all your help, I apologize for all of the posts.

  14. #14
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    if that is all the data you have/need.. you can even make it a little shorter

    PHP Code:
    <counties>
        <
    county name="Adams">
            <
    data rate="0.0" />
            <
    data rate="10.3" />
            <
    data rate="61.3" />
        </
    county>
    </
    counties
    using the above XML schema.. I would make the "Adams" movieClip that is on the stage..have the same instance name (Adams)


    here is a quick example..Im sure you can adapt to your needs..

    ther are only two clips (counties) on the stage..

    their instance names are:

    Adams
    county2

    (same as the names in the XML file)

    XML FILE I USED:

    Code:
    <counties>
        <county name="Adams">
            <data rate="0.0" />
            <data rate="10.3" />
            <data rate="61.3" />
        </county>
    
        <county name="county2">
            <data rate="12" />
            <data rate="10.5" />
            <data rate="66.9" />
        </county>
    </counties>
    Attached Files Attached Files

  15. #15
    Junior Member
    Join Date
    Jun 2009
    Posts
    16
    Ok, I think I got it now. My next question is how do I call my xml file from flash?

    I bet you really regret responding to my thread now : )

  16. #16
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    ?? huh ?? did you look at the file (.fla) I attached for you?

    its basically your whole project done for you..

  17. #17
    Junior Member
    Join Date
    Jun 2009
    Posts
    16
    My bad, I didn't see the attached file. Sorry.

  18. #18
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    no problem... it is all there for you...

    the only thing you would need to do is:

    1.) populate the XML file with all your counties (or whatever ones you need to add data to)
    2.) name all the movieClip/counties on the stage to match the names in the XML file
    3.) add a few lines of code that when you rollOver the movieClip/county (already there)..the data that is nested inside each clip gets display in a text field..or 3 separate textfields..(not already there)

    when you rollover the clips you will see the data trace out already..

  19. #19
    Junior Member
    Join Date
    Jun 2009
    Posts
    16
    This might be a non-issue but I'm going to ask; Each county in the map is a button and not a movie clip. Do the counties need to be movie clips?

  20. #20
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    shouldnt matter.. however you can make a movieClip..and assign button events to it..

    ie:

    movieClip1.onPress = function(){
    //do something here;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center