Search code examples
xmlflashactionscript-3actionscriptas3crypto

XML in flash that should fetch data from an external xml file


Well, i am new in this flash thing and in the learning stage. on the stage are four buttons. they will behave like map. now what i want to do is, that i want to use xml. when i click on button, it should display some text, like title, description, address etc below the map and the these details should come from an external xml file. i am pretty confused over here. can anybody suggest what i should do?

Thanks in advance....

enter image description here


Solution

  • First you need to create a class for the single map peace which will has all parameters (like title, description, address etc) in the link #2 you can read about creating classes in as3. After you will need to create xml file and describe there every peace of your map, this xml should be consistent with your class. So if you have class:

    public class MapElement{   
      // ------- Properties ------- 
      private var title: String;
      private var description: String;
      private var address : String;
      // other code
    } 
    

    you xml should be something like this:

    <mapelement>
      <title>el1</title>
      <description>some description 1</description>
      <address>first eddress</address >
    </mapelement>
    <mapelement>
      <title>el2</title>
      <description>some description 2</description>
      <address >second address</address >
    </mapelement>
    

    So later it will be easy for you to create mapelements objects in flash for every mapelement node of your xml file. You also can add x and y coordinates so you will know where to put this map elements on the stage.

    So later you will need to create on click event listeners for this elements, the best will be to add them into the MapElement class, so every time you create MapElement it already has event listener and you don't need to worry about it later. So this will be onClick event, which will display parameters of this map element. I will put some links which should help you with more technical details.

    Some helpful links:

    1. load xml into flash
    2. basic oop in as3
    3. event listeners