FusionMaps and Flash > Handling Click Events |
You can easily handle the click events for entities on the map in your Flash movies. That is, whenever a user clicks on an entity, you can be notified of the same in your Flash movie. Here we'll see how to do this. |
Adding link to XML |
To enable your parent movie to track links in FusionMaps maps, you need to add S- before every link specified in the XML data document. This instructs the maps to convey the link to its parent SWF movie. An example is given below: <entity id='NA' value='49' link='S-NA'/> Here, S- is the prefix to indicate that this link should be bubbled up to parent SWF. When this link is bubbled up, parameter is passed to the event handler. We'll see this in the example below. If you need to pass multiple parameters, one way would be to use a comma to separate each new value. Then String.split the parameter into individual values in the called function. This is a simple method that would only work with string values. Let's now put all this learning into a practical example to see its usage. |
Creating a link handler example |
In this example, we'll create a copy of MyFirstMap.fla and save it as ClickHandler.fla. We'll define the link events for all the entities on the map. Each entity, when clicked, would call a function, which in turn would just output the name of the entity. In real life scenarios, you can do better things with this data. The actions in the new movie would now contain the following: |
/** //Note: If you're loading multiple maps in your Flash movie, you //To create the map, you now need to import the Class of the // -------------- Actual Code to create the map ------------//
|
As you can see above, we've defined the link for each entity on the map. The entities, when now clicked, will invoke linkClicked event of the listener object and pass the parameter to the same. In the body of this function, we've just traced out the entity name received as parameter. In your code, you could pass indexes of data and then deal with it the way you want to. When you now run this code and click on any entity, you'll see the name of entity in output window as under: |