Implement a Map Using the Google Map API for Flash

Implement a Map Using the Google Map API for Flash

Tutorial Details

Twice a month, we revisit some of our readers’ favorite posts from throughout the history of Activetuts+. This tutorial was first published in May, 2009.

In this tutorial we’ll see how we can create a map in Flash using the Google Map API. We’ll cover some of the basics such as zooming in on the map and adding some controls. We’ll also look at how we can add markers to our map and how we can load data using an XML file.


Step 1: The Google Map API Key

Before we can start creating our map in Flash we need to setup a few things. To use the Google Map API you will need a personal API Key. To get this go to http://code.google.com/intl/nl/apis/maps/documentation/flash/ and click the link on the right side of the page "Sign up for a Google Maps API Key".

google maps api for flash

Step 2: Sign Up

Clicking the "Sign up for a Google Maps API Key" link brings us to the next page where we can generate our personal API Key. Scroll down the page, agree with the terms and conditions (you could read these too if you’re really interested) and add the url of the website where you want to use the application (you will need a different API Key for every domain where you want to place a map). After that, click "Generate API Key".

google maps api for flash

Step 3: Save It!

Now you’ll see your personal API Key for the selected domain. Copy the API Key and paste or save it somewhere as we’ll need it very soon.

google maps api for flash

Step 4: The Google Map SWC Component

Ok, now we have our API Key but we still need one more thing before we can start to create our map in Flash. We need to download the Google Map SWC component. To do so, go to http://code.google.com/intl/nl/apis/maps/documentation/flash/ and click "Download the Google Maps API for Flash SDK". A popup window will appear, choose to Save the "sdk.zip" file and download it.

google maps api for flash

Step 5: Install the SDK Component

Now we need to install the SDK component to use it in Flash. To do so, navigate to the location where you saved the Google Maps API for Flash SDK and find the non-Flex version of the interface library. In my case this is (lib/map_1_9.swc). Now copy the "map_1_9.swc" file.

google maps api for flash

Step 6: Folders

Afterwards, if you have Flash currently open, quit the application and search for this folder:

  • (Windows) C:\Program Files\Adobe\Adobe Flash CS3 (or your Flash version)\en (or your language)\Configuration\Components
  • (Mac OS X) Macintosh HD/Applications/Adobe Flash CS3 (or your Flash version)/Configuration/Components

Inside that folder create a new folder named "google" and Paste the "map_1_9.swc" file inside it. Flash is now set up to support the Google Maps API for Flash.

google maps api for flash

Step 7: New ActionScript 3.0 File

Ok. That’s all done and dusted! Now we can finally start creating our map in Flash. Start Flash CS3 or CS4 and create a new ActionScript 3.0 file, default stage size (550 x 400).

google maps api for flash

Step 8: Save It!

Now simply save the file; hit "Ctrl+S" or go to File > Save in the menu. Save it to the location you want and name it whatever you want. I’ll name it "google_map".

google maps api for flash

Step 9: The GoogleMapsLibrary

Open the Components panel "Ctrl+F7" or click Window > Components in the menu and drag the GoogleMapsLibrary onto the stage.

google maps api for flash

Step 10: The Actions Layer

Create a new layer, double-click on its name and rename it to "actions".

google maps api for flash

Step 11: Import..

Now with the actions layer selected open the actions panel by hitting "F9" or clicking Window > Actions. Add these lines of code:

import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapType;
google maps api for flash

Step 12: Create the Map

Now let’s add the map! When we load the movie this piece of code will create a map and set it on the stage. Inside the code we see the variable "map.key"; here we have to add our personal API Key. Open the file where you saved the API Key and Copy/Paste it into the variable.

// Create The Map
var map:Map = new Map();
map.key = "Your API Key here";
map.setSize(new Point(stage.stageWidth, stage.stageHeight));
this.addChild(map);
google maps api for flash

Step 13: Test Movie

Ok, now go and test your movie "Ctrl+Enter" or click Control > Test Movie in the menu and you will see that you’ve just created a map.

google maps api for flash

Step 14: Controls

At this stage we can only drag the map around. That’s not really what we’re looking for, so let’s add some controls to the map which will allow us to zoom and move about. To add controls to our map we need to update our code. First we need to call a few extra classes:

import com.google.maps.controls.ZoomControl;
import com.google.maps.controls.PositionControl;
import com.google.maps.controls.MapTypeControl;

After that we need to create a new function to call once the map is created. We name that function "onMapReady()". Inside this function we add our controls to the map.

function onMapReady(event:MapEvent):void {
  map.addControl(new ZoomControl());
  map.addControl(new PositionControl());
  map.addControl(new MapTypeControl());
}

Now we just need to call the "onMapReady()" function whenever our map is loaded. To do that we need to add a extra line to our first piece of code.

map.addEventListener(MapEvent.MAP_READY, onMapReady);

Our full code now looks like this:

import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapType;
import com.google.maps.controls.ZoomControl;
import com.google.maps.controls.PositionControl;
import com.google.maps.controls.MapTypeControl;

// Create The Map
var map:Map = new Map();
map.key = "Your API Key Here";
map.setSize(new Point(stage.stageWidth, stage.stageHeight));
map.addEventListener(MapEvent.MAP_READY, onMapReady);
this.addChild(map);

function onMapReady(event:MapEvent):void {
  map.addControl(new ZoomControl());
  map.addControl(new PositionControl());
  map.addControl(new MapTypeControl());
}
google maps api for flash

Step 15: More..

Now test your movie "Ctrl+Enter" or click Control > Test Movie in the menu and you will see our map now has controls. We’re able to zoom in and even change our map to Satellite, Hybrid and Terrain view. That’s very cool but we want more..

google maps api for flash

Step 16: Latitude and Longitude

Let’s zoom into a specific location once our map loads for the first time. Say I’m a surfer and I want to create a map of the surf spots in my home town. We don’t want people to manually have to zoom in and search for the area, so we’ll fix that in a sec. The only thing we have to add is one small line of code to our "onMapReady()" function.

map.setCenter(new LatLng(28.74659,-13.93447), 9, MapType.HYBRID_MAP_TYPE);

What we actually do here is create a new LatLng point on the map. First we specify 2 values: the "latitude" and the "longitude" from our region. Then we set our zoom value; I opted to use 9. The zoom ranges from 0 to about 16 (this can vary from region to region). Lastly we set the map type; I opted here for the HYBRID_MAP_TYPE.

Our "onMapReady()" function now looks like this:

function onMapReady(event:MapEvent):void {
  map.setCenter(new LatLng(28.74659,-13.93447), 9, MapType.HYBRID_MAP_TYPE);
  map.addControl(new ZoomControl());
  map.addControl(new PositionControl());
  map.addControl(new MapTypeControl());
}

If we test our movie you can see that lots of things have changed. Once the map is loaded we zoom into our specific region and our map type is now Hybrid. To determine the latitude and longitude for your region you could use Google Earth or an online tool like http://itouchmap.com/latlong.html.

google maps api for flash

Step 17: Add a Marker

Now let’s add a simple marker to our map. Just add 2 more classes:

import com.google.maps.overlays.MarkerOptions;
import com.google.maps.overlays.Marker;

and update the "onMapReady()" function with this piece of code:

var marker:Marker = new Marker(
							     new LatLng(28.74659, -13.93447)
		     		            );
map.addOverlay(marker);

Again we create a LatLng point with some specific latitude/longitude values for our location. Then we call the "addOverlay()" to put our marker on the map. Our full code now looks like this:

import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapType;
import com.google.maps.controls.ZoomControl;
import com.google.maps.controls.PositionControl;
import com.google.maps.controls.MapTypeControl;
import com.google.maps.overlays.MarkerOptions;
import com.google.maps.overlays.Marker;

// Create The Map
var map:Map = new Map();
map.key = "ABQIAAAAUeTGkbea0ftVnzbVMwAPKxT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTlsMw9FdPd5mJqEw01CzwnlVdxDw";
map.setSize(new Point(stage.stageWidth, stage.stageHeight));
map.addEventListener(MapEvent.MAP_READY, onMapReady);
this.addChild(map);

function onMapReady(event:MapEvent):void {
  map.setCenter(new LatLng(28.74659,-13.93447), 9, MapType.HYBRID_MAP_TYPE);
  map.addControl(new ZoomControl());
  map.addControl(new PositionControl());
  map.addControl(new MapTypeControl());

  var marker:Marker = new Marker(
							     new LatLng(28.74659, -13.93447)
		     		            );
  map.addOverlay(marker);
}

Go and test your movie. You’ll see our marker on the map.

google maps api for flash

Step 18: Still More..

Now let’s take everything to the next level. We have a map with zoom controls and a marker. What more do we need? Well I’ll tell you. We need MORE MARKERS, TOOLTIPS, INFO WINDOWS and we want to load everything from an XML file. So let’s get started. First we’ll create our XML file. Open your Favorite XML editor and create this file:

<?xml version="1.0" encoding="utf-8"?>
 <map_xml>

  <location>
   <lat>28.74659</lat>
   <lon>-13.93447</lon>
   <name_tip>Majanicho</name_tip>
   <title_tip><![CDATA[Majanicho]]></title_tip>
   <content_tip><![CDATA[Majanicho is a very good surf spot for longboarding it offers very long rides.]]></content_tip>
  </location>

  <location>
   <lat>28.738764</lat>
   <lon>-13.955126</lon>
   <name_tip>Derecha de los Alemanes</name_tip>
   <title_tip><![CDATA[La Derecha de los Alemanes]]></title_tip>
   <content_tip><![CDATA[La Derecha de los Alemanes is another very good spot for longboarders but shortboarders will have some epic days out here to.]]></content_tip>
  </location>

  <location>
   <lat>28.741022</lat>
   <lon>-13.951821</lon>
   <name_tip>The Bubbel</name_tip>
   <title_tip><![CDATA[The Bubbel aka La Derecha]]></title_tip>
   <content_tip><![CDATA[The Bubbel is one of the most famouse waves in Fuerteventura its a really hollow reef break and it has some epic barrels on offer.]]></content_tip>
  </location>

 </map_xml>

Step 19: onMapReady()

Once our map is loaded we need to pull the XML data into our Flash file. Create a new function named "xmlLoader()" and we’ll call that function in our "onMapReady()" function. First we need to delete the code we added to create our marker just a few steps before. Then we’ll add the line to call the "xmlLoader()" function. Our "onMapReady()" function should now look like this:

function onMapReady(event:MapEvent):void {
  map.setCenter(new LatLng(28.74659,-13.93447), 9, MapType.HYBRID_MAP_TYPE);
  map.addControl(new ZoomControl());
  map.addControl(new PositionControl());
  map.addControl(new MapTypeControl());
  xmlLoader();
}

Next we want to create the "xmlLoader()" function.

function xmlLoader(){

}

In the next step we’ll fill it up.


Step 20: Load XML

Ok here we are. Let’s load our XML data. Inside the "xmlLoader()" function we add this code:

 function loadXML(e:Event):void{
	 XML.ignoreWhitespace = true;
	 var map_xml:XML = new XML(e.target.data);
 }// end of loadXML function

 var xmlLoader:URLLoader = new URLLoader();
 xmlLoader.addEventListener(Event.COMPLETE, loadXML);
 xmlLoader.load(new URLRequest("xml.xml"));

This will get us our XML data to work with.


Step 21: Loop Through the Locations

As we have 3 locations in our XML file we’ll need to create a "For" loop and store all the data in some Arrays. Inside our "loadXML()" function we add this piece of code to create the For loop:

for (var i:Number = 0; i < map_xml.location.length(); i++){
		 trace(map_xml.location[i].title_tip);

	 }// end of for loop

To test if things are working for us we’ll trace the "title_tip" variable. Test your movie and you should get the following output:

google maps api for flash

Step 22: Variables

Next we have to create some variables to store our data loaded from the XML file. Inside our For loop we add these variables:

var latlng:LatLng = new LatLng(map_xml.location[i].lat, map_xml.location[i].lon);
var tip = map_xml.location[i].name_tip;
var myTitle:String = map_xml.location[i].title_tip;
var myContent:String = map_xml.location[i].content_tip;

If you want you can delete the "trace()" line we used before. Our For loop now looks like this:

for (var i:Number = 0; i < map_xml.location.length(); i++){

		 var latlng:LatLng = new LatLng(map_xml.location[i].lat, map_xml.location[i].lon);
		 var tip = map_xml.location[i].name_tip;
		 var myTitle:String = map_xml.location[i].title_tip;
		 var myContent:String = map_xml.location[i].content_tip;
	 }// end of for loop

Step 23: Additional Markers..

Ok! We need to add a marker to the map for each of our three locations. Now that we have all the data stored in our variables we’ll have to create a new function named "createMarker()". Inside our "loadXML()" function we add this new function:

// Add Markers On The Map
function createMarker(latlng:LatLng, number:Number, tip, myTitle, myContent):Marker {
               var i:Marker = new Marker(
										 latlng,
										 new MarkerOptions({
                                                           hasShadow: true,
				                                           tooltip: ""+tip
                                                           })
										 );
               return i;
}// end function createMarker

We still need to call this "createMarker()" function in order to see our markers on the map. To do that we need to add a extra line of code at the end of our For loop:

map.addOverlay(createMarker(latlng,i, tip, myTitle, myContent));

This is what our "loadXML()" function should look like now:

function loadXML(e:Event):void{
	 XML.ignoreWhitespace = true;
	 var map_xml:XML = new XML(e.target.data);

	 for (var i:Number = 0; i < map_xml.location.length(); i++){

		 var latlng:LatLng = new LatLng(map_xml.location[i].lat, map_xml.location[i].lon);
		 var tip = map_xml.location[i].name_tip;
		 var myTitle:String = map_xml.location[i].title_tip;
		 var myContent:String = map_xml.location[i].content_tip;

		 map.addOverlay(createMarker(latlng,i, tip, myTitle, myContent));
	 }// end of for loop

	 // Add Markers On The Map
	 function createMarker(latlng:LatLng, number:Number, tip, myTitle, myContent):Marker {
               var i:Marker = new Marker(
										 latlng,
										 new MarkerOptions({
                                                           hasShadow: true,
				                                           tooltip: ""+tip
                                                           })
										 );
               return i;
      }// end function createMarker
 }// end of loadXML function

Test your movie and you will see the markers on the map! Note that our 3 points are very close to each other so you may want to zoom in a bit to see them more clearly.

google maps api for flash

Step 24: Info Windows

Finally we need to add some Info Windows. If we click on the markers we’ll then get some information about their locations. To do so we need to add 2 more classes:

import com.google.maps.InfoWindowOptions;
import com.google.maps.MapMouseEvent;

..a little more code to our "createMarker()" function..

i.addEventListener(MapMouseEvent.CLICK, function(event:MapMouseEvent):void
        {
         map.openInfoWindow(event.latLng, new InfoWindowOptions({
                                      titleHTML: ""+myTitle,
                                      contentHTML: ""+myContent
                                                               }));

		});

Now test your movie and you’ll see that our markers are now clickable and that they create an info window with text from the XML file.

google maps api for flash

Conclusion

Thats it! Take a look at our final code:

import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapType;
import com.google.maps.controls.ZoomControl;
import com.google.maps.controls.PositionControl;
import com.google.maps.controls.MapTypeControl;
import com.google.maps.overlays.MarkerOptions;
import com.google.maps.overlays.Marker;
import com.google.maps.InfoWindowOptions;
import com.google.maps.MapMouseEvent;

// Create The Map
var map:Map = new Map();
map.key = "Your API Key Here";
map.setSize(new Point(stage.stageWidth, stage.stageHeight));
map.addEventListener(MapEvent.MAP_READY, onMapReady);
this.addChild(map);

function onMapReady(event:MapEvent):void {
  map.setCenter(new LatLng(28.74659,-13.93447), 9, MapType.HYBRID_MAP_TYPE);
  map.addControl(new ZoomControl());
  map.addControl(new PositionControl());
  map.addControl(new MapTypeControl());
  xmlLoader();
}

function xmlLoader(){
 function loadXML(e:Event):void{
	 XML.ignoreWhitespace = true;
	 var map_xml:XML = new XML(e.target.data);

	 for (var i:Number = 0; i < map_xml.location.length(); i++){

		 var latlng:LatLng = new LatLng(map_xml.location[i].lat, map_xml.location[i].lon);
		 var tip = map_xml.location[i].name_tip;
		 var myTitle:String = map_xml.location[i].title_tip;
		 var myContent:String = map_xml.location[i].content_tip;

		 map.addOverlay(createMarker(latlng,i, tip, myTitle, myContent));
	 }// end of for loop

	 // Add Markers On The Map
	 function createMarker(latlng:LatLng, number:Number, tip, myTitle, myContent):Marker {
               var i:Marker = new Marker(
										 latlng,
										 new MarkerOptions({
                                                           hasShadow: true,
				                                           tooltip: ""+tip
                                                           })
										 );
			   i.addEventListener(MapMouseEvent.CLICK, function(event:MapMouseEvent):void
																			  {
																			  map.openInfoWindow(event.latLng, new InfoWindowOptions({
																																	 titleHTML: ""+myTitle,
																																	 contentHTML: ""+myContent
																																	 }));

																			  });
               return i;
      }// end function createMarker
 }// end of loadXML function

 var xmlLoader:URLLoader = new URLLoader();
 xmlLoader.addEventListener(Event.COMPLETE, loadXML);
 xmlLoader.load(new URLRequest("xml.xml"));
}

Test your movie Ctrl+Enter to check the outcome. You’ll have your own xml based Flash map! You can use it on your website, edit the locations as you want, it’s up to you. Go ahead and experiment, if you have any cool results be sure to share them with us.

I hope you liked this tutorial, thanks for reading!

Niels Musschoot is tunafish on Activeden
Add Comment

Discussion 95 Comments

Comment Page 1 of 21 2
  1. Lost-Soul says:

    1st >:)

    look nice , thanks pro :D

  2. Salvo says:

    Really good! i think that tutorials about external services with Flash/Flex are less common on the web… so keep going this way (and thanks a lot) :-)

  3. Farquarto says:

    Really nice tut thanks Niels.

  4. Cool Niels is an interesting component and your code is great, I like it because is very detailed.

  5. Fred says:

    Very nice tutorial.
    Do you know if it works with KML?
    I made an application with G Maps and Joomla wich used KML to add markers or other things.
    We can update those markers with G Hearth.
    Someone does know something about it?

  6. Pamela Fox says:

    Great! Can we add this to the documentation?

  7. Cool! Think I’ll try it! :)

  8. motoracer says:

    Wszystko fajnie śmiga ale kiedy usunę mc w którym mam mapę a potem do znowu dodam z biblioteki kompilator wyrzuca mi błędy:

    Error: Object not initialized
    at com.google.maps.wrappers::Wrapper$/checkValid()
    at com.google.maps.wrappers::IMapWrapper/isLoaded()
    at com.google.maps::Map/isLoaded()
    at com.google.maps::Map/::internalSetSize()
    at com.google.maps::Map/setSize()
    at content_fla::pageContent_8/setupMap()

    • Ian Yates says:
      Staff

      I’d thought it fair just to run that through translate.google.com first ;-)

      “All good but when I sail away with whom I am mc map and then to add the library again, the compiler throws me errors:”

      My Polish isn’t perfect, but I doubt that’s 100% accurate…

    • elfymer says:

      This is related to .

      “Non-Map classes cannot be used before onMapReady event”

      This happens when you load your map class to another instance from another component module(flex) / movieclip (flash)

      To be more specific your setSize() map statement should be executed within onMapReady function.

      Hope that helps.

  9. Rob says:

    Nice tut, works fine. Now let’s fiddle some more with the Google API.

  10. Maziman says:

    Very nice tutorial! Really beat the Google tutorial by miles!

  11. Diego SA says:

    Cool! I’ve always looked for tutorials about it. Now I know how you guys do that! Ooooh look, now I can find the way for home, hehe!
    Thanks!

  12. wetspiz says:

    Thanks, really nice tuto!!

  13. NetHawk says:

    Great Tut. Vista users should note, that the components goes to:

    C:\Users\(UserName)\AppData\Local\Adobe\Adobe Flash CS3 (or your Flash version)\en (or your language)\Configuration\Components

  14. spyece says:

    thanks for sharing this

  15. Oren Roth says:

    Good tut!

    too bad that google didn’t map my contry, so it’s not that much usefull for me….

    thanks though!

  16. Tim says:

    Thanks for this nice tutorial.

    Does someone know how to add custom icons (markers) inside this script?

    Thanks in advance

  17. dave says:

    What about adding directions?

  18. Svetlana says:

    Good tut! Thanks for sharing!

  19. sagoo says:

    cool! so easy to follow. great tut. keep up the good work.

  20. Pheyonagh says:

    this tutorial is amazing, well written and easy to understand. Exactly what i was looking for. Keep up the good work!

  21. flyx says:

    great tuto!!! muchas graxias por la ayuda realmente lo realice en muy poco tiempo y luce muy bien en la pagina, gracias totales!!!

  22. Elagbariel says:

    Great idea, great tutorial

  23. Buster says:

    This is cool but is there a way to create a page where a member can submit lattitude, longitude, title and description via a php or html page?

  24. Bruno Arruda says:

    nice tuto. but i have a quetion!

    I did decrease the map with respect to the stage, but would like to know how I placed in the center or in a pre-determined point.

  25. Bruno Arruda says:

    I have a question, I got the map to reduce the size of the stage, but I can´t centralize or even put in a pre-determined point. Would do that?

  26. PT: Muito show esse tutorial… em pensar que eu tinha feito este mapa (http://www.imobiliariaschneider.com.br/mapa_imoveis.jsp) todo estático… e tenho q ficar atualizando :(

    Com essa solução posso pegar no sistema as coordenadas do imóvel e posicioná-lo aonde eu quero hehe…

    Mais uma vez.. muito legal o tutorial.

    ——————————————————————————————————–

    EN: Very nice tutorial that … to think that I had made this map (http://www.imobiliariaschneider.com.br/mapa_imoveis.jsp) all static … and I q be updating: (

    With this solution in the system can get the coordinates of the property and place it where I want to … hehe

    Again .. very nice the tutorial.

    ——————————————————————————————————–

    @gust4vo

  27. Jack says:

    Hi, can this possible work with Flash Lite as well?

  28. manoupi says:

    Great Tut Thanks a billion!

  29. Akram says:

    hello thanx for the really amazing tut :)
    i’ve done it and i’m very happy with it :D

    but i really want to know how to add a KML layer
    please help me
    in as2 i’ve used:
    map.addKMLLayer({path:”Restaurants.kml”});
    but here in as3 i couldn’t use it
    please tell me how i’m checking this page daily to find how to solve it
    please note that the “Restaurants.kml” is a local file aside the flash file

    • Ali says:

      Can you please tell me that how I can set my map at different locations ? Like I am a Pakistani so I like to set Pakistan as default …Any clue?

  30. rayo says:

    excelent…it work…..can u tell me how to add a custom icon to the existing script….

  31. Liquidooo says:

    GREAT TUT!!!
    All is working when im testing in flash,it loads everything.But when I put into my web folder – not working!?

    It cant load anything!Ive changed into .swf line xml.xml to google.xml !
    Help!I cant see a problem!
    Tnx!

  32. Liquidooo says:

    This is AS3 I need AS2…

  33. tim says:

    Seems like a great tutorial but I am getting and error on step 14. Can someone please help.

    I am using Flash CS3 AS3

    Here is the coding

    import com.google.maps.LatLng;
    import com.google.maps.Map;
    import com.google.maps.MapEvent;
    import com.google.maps.MapType;
    import com.google.maps.controls.ZoomControl;
    import com.google.maps.controls.PositionControl;
    import com.google.maps.controls.MapTypeControl;

    //Create the Map
    var map:Map = new Map();
    map.key = “ABQIAAAAL57H9kquw91x7iwKECd57RQo58NiUu8xQSUISegU9IE_NodVsxSmpH5pAMaM18mY2T6vfGiTPj7SFw”
    map.setSize(new Point(stage.stageWidth, stage.stageHeight));
    map.addEventListener(MapEvent.MAP_READY, onMapReady);
    this.addChild(map);

    function onMapReady(event:Map):void{
    map.addControl(new ZoomControl());
    map.addControl(new PositionControl());
    map.addControl(new MapTypeControl());
    }

    Here is the error:
    TypeError: Error #1034: Type Coercion failed: cannot convert com.google.maps::MapEvent@510f2c1 to com.google.maps.Map.
    at MethodInfo-336()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at com.google.maps.wrappers::BaseEventDispatcher/dispatchEvent()
    at com.google.maps.wrappers::EventDispatcherWrapper/dispatchEvent()
    at com.google.maps.core::MapImpl/configureMap()
    at com.google.maps.wrappers::IMapWrapper/configureMap()
    at com.google.maps::Map/onBootstrapInitComplete()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at com.google.maps::ClientBootstrap/createFactory()
    at com.google.maps::ClientBootstrap/executeNextFrameCalls()
    at flash.utils::Timer/_timerDispatch()
    at flash.utils::Timer/tick()

    • magron says:

      Hi there!! really great tut!!
      i m also having this errors:

      Error – Step 19/20
      Scene 1, Layer ‘AS’, Frame 1, Line 1180: Call to a possibly undefined method xmlLoader. xmlLoader( );

      And when i take yours files, its works well, but when re-save it on CS4, its still loading the place, but not showing the marks anymore.. and shows up this errors:..

      TypeError: Error #1088: The markup in the document following the root element must be well-formed.
      at MethodInfo-1621()
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at flash.net::URLLoader/onComplete()

      any suggest ?

  34. Newbie says:

    I am a total Newbie

    How do I add pictures to the info boxes and how to i create a button to turn on and off the markers.

    I am totally new to AS3 and XML.

    Any help would be awesome

  35. Fred Freedber says:

    Could you continue on with a Part II of this tutorial which includes geocoding and having a input field to search for the closest marker by ZIP? Awesome tutorial

  36. Scott G says:

    Everything was working great until the last couple steps, then I get this error:

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at com.google.maps.overlays::Marker()
    at GoogleMap_fla::MainTimeline/createMarker()
    at GoogleMap_fla::MainTimeline/loadXML()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()

  37. Scott G says:

    Nevermind, got it!

  38. Potia says:

    Hi Nice tutorial of yours :>

    I’m a newbie for actionscript 3.0

    I would like to change the marker to the other pic icon.
    Does anyone know the actionscript to change the custom marker?

    Thank u.

  39. Jarno says:

    How do I add an Info Window to the marker created in step 17 without using XML?

  40. mibbles says:

    great tutorial. many thanks.

    i’m using large xml files with 100s of markers. when it’s processing the xml, the whole app freezes. so i put a “loading bar” into the loop and output a progress trace. e.g. within the loop

    for (var i:Number = 0; i < map_xml.location.length(); i++){
    trace(i);
    this.myLoadBar.width = ( Math.round(i/map_xml.location.length()*100) );

    the problem is the loading bar doesnt update as expected. the app remains frozen until all markers in the xml are processed and only then dumps the trace expected and the loading bar gets set to 100%…

    can anyone advise why this is happening ?

    • danee says:

      prob memory leak issue from the large xml you are loading? You may want to split that data into smaller chunks (separate xmls) only displaying what you need to at a certain time. ORRR you can try using flash remoting it behaves better on large chunks of data. In general you want to try and only load what you need at any given time.

  41. Yan says:

    Hello great tut,

    how can i change the marker with my own on this script

    can anybody help me..???, pleaseee

    • patrick says:

      below is the code from this tut with some added lines for the custom marker. markerIcon is a movieclip in my library which is exported for AS.
      hope that helps.

      function createMarker(latlng:LatLng, number:Number, tip, myTitle, myContent):Marker {
      var i:Marker = new Marker(latlng, new MarkerOptions({

      //custom marker

      //icon:new markerIcon(),
      //iconAlignment:MarkerOptions.ALIGN_TOP,

      //change the color of the default google marker
      hasShadow:true,
      tooltip:”"+tip,
      strokeStyle: new StrokeStyle({color: 0xff3322}),
      fillStyle: new FillStyle({color: 0xff3344, alpha: 0.8})
      }));

      //function for info window click
      i.addEventListener(MapMouseEvent.CLICK, infoClick);
      function infoClick(event:MapMouseEvent):void {
      map.openInfoWindow(event.latLng, new InfoWindowOptions({titleHTML:”"+myTitle,contentHTML:”"+myContent}));
      }

      return i;
      }

  42. patrick says:

    sweet tut.
    is there a way to have an image inside the infoWindow?

  43. Bob Hunter says:

    Great tutorial. I’ve read a lot of tutorials on Flex and Google Maps, but this one was the best at explaining what needs to be done.

  44. francesco says:

    Great tutorial, but I have a question..(I’m a newbie with Flash..)..How can I add it into an existing project? It works perfectly when I start a new project, but when I try to use it in a website I made sometime ago I can’t see the “google” entry in the components window..

  45. Xenocide says:

    Awesome Tutorial! I am a newbie to flash as well and want to add more elements, like links to the side that when clicked center on that location on the map as well as a zipcode search that shows the locations within so many miles. I am looking over the Google API but am not sure how to integrate those features.

  46. Kissa says:

    THIS TUTORIAL SAVED MY LIFE!

  47. Roy says:

    I am also working on a Tooltip with images and text through xml.
    I want to do this with the customContent property that calls a external class. I’ve tried many tutorials and forums but I can’t get it to work. The tooltip remains empty or I am getting errors.

    Can someone help me with this thank you.

  48. Benjamin Cankalp says:

    I loved the Tutorial .. but i want to know if it is possible to make the same tutorial for adobe flash cs4

Comment Page 1 of 21 2

Add a Comment

To add a code snippet to your comment, please wrap your code like so: <pre name="code" class="html">YOUR CODE</pre>. You can replace the class name with "js," "css," "sql," or "php." If there are any "<" or ">" within your code, please search and replace them with: &lt; and &gt; respectively.