Google Maps Flash API Tutorial
This is the second part of the Actionscript 3.0 Google Maps tutorial. In part 1 you learnt how to set up the developer environment. Now it’s time for the real fun part, where you get to write the code. You may want to try some of the simpler tutorials on the Google code site, just to get you feeling more comfortable with the API.
First download the API from Google code
package code { import flash.display.Sprite; import flash.display.MovieClip; import flash.events.Event; import caurina.transitions.Tweener; public class GMapMain extends Sprite { public var getMapView:GMapView; public var getMapControl:GMapControl; public var mapForm2:MovieClip; public function GMapMain () { addEventListener(Event.ADDED_TO_STAGE, checkStage); getMapControl = new GMapControl(); addChild(getMapControl); } public function checkStage(e:Event):void { getMapControl.x = 160; getMapControl.y = 80; var getStage2 = stage.getChildAt(0); trace ("getStage2 = " +getStage2); trace(stage); } } }
First create the document class – GMapMain.as as shown above. The primary function of this class is to initialize the controller class – GMapControl.as. Since we are using MVC model. The GMapMain adds an even listener on the stage – checkStage, that checks to see if the GMapMain itself has been added to the stage. after this event is fired an instance of GMapControl – getGmapControl is added to the display list.
import flash.display.Sprite; import flash.events.MouseEvent; import fl.controls.*; import flash.display.*; import flash.events.*; import flash.text.*; import com.google.maps.Map; public class GMapControl extends MovieClip { public var getButton:Button; public var getForm:TextInput; public var getTo:TextInput; public var getStage2; public var getMapView:GMapView; static var getAddFrom:String; static var getAddTo:String = new String("hello to"); <span class="style3">public function</span> GMapControl () { trace("GMapControl"); getMapView = new GMapView(); addEventListener(Event.ADDED_TO_STAGE, checkStage2); }
Pages: 12
Leave a Reply