Hello to all!
I know this is the total newbie question (and i´m one), but I can´t make it work.
I made a class to create and handle a google map in my swf and everything works very well. But I want to make my layout completely liquid. To acomplish this, I need to call the stage from the class… But it doesn´t seem to be so easy…
I´ve searched everything but still haven´t found how to do it…
the code is bellow:
package classes.gui{
import flash.geom.Point;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
import flash.events.MouseEvent;
import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapType;
import com.google.maps.MapOptions;
import com.google.maps.InfoWindowOptions;
import com.google.maps.MapMouseEvent;
import com.google.maps.MapMoveEvent;
import com.google.maps.controls.*;
import com.google.maps.services.*;
import com.google.maps.styles.*;
import com.google.maps.overlays.*;
public class Gmap extends MovieClip {
private var zoomRate:Number=1;
private var dir:Directions;
public var map:Map = new Map();
public var stageMC:MovieClip = new MovieClip();
public var _stage:Stage = stageMC.stage;
public function Gmap():void {
this.addChild(stageMC);
map.addEventListener(MapEvent.MAP_READY, onMapReady);
map.key="my_original_key_comes_here";
//the line below works
//map.setSize(new Point(980, 390));
//the next three lines dont work
map.width = _stage.stageWidth - 120;
map.height = (_stage.stageHeight/100) * 60;
//map.setSize(new Point(stage.stageWidth - 120, (stage.stageHeight/100) * 60));
this.addChild(map);
}
// set map properties
private function onMapReady(event:Event):void {
var bottomRight:ControlPosition=new ControlPosition(ControlPosition.ANCHOR_BOTTOM_RIGHT,16,10);
var myMapTypeControl:MapTypeControl = new MapTypeControl();
myMapTypeControl.setControlPosition(bottomRight);
map.addControl(myMapTypeControl);
var topLeft:ControlPosition=new ControlPosition(ControlPosition.ANCHOR_TOP_LEFT,16,10);
var zControl:ZoomControl = new ZoomControl();
zControl.setControlPosition(topLeft);
map.addControl(zControl);
map.setCenter(new LatLng(-15.501119, -47.504229), 12);
dir = new Directions();
dir.addEventListener(DirectionsEvent.DIRECTIONS_SUCCESS, onDirLoad);
dir.addEventListener(DirectionsEvent.DIRECTIONS_FAILURE, onDirFail);
dir.load("-15.501119, -47.504229 to -15.9814,-47.820805");
map.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel);
}
private function onMouseWheel(e:MouseEvent):void {
var zoom:Number=map.getZoom();
if (e.delta>0) {
map.setZoom(zoom+zoomRate);
} else {
map.setZoom(zoom-zoomRate);
}
}
private function onDirFail(event:DirectionsEvent):void {
trace("****!");
}
private function onDirLoad(event:DirectionsEvent):void {
var dir:Directions=event.directions;
map.clearOverlays();
map.addOverlay(dir.createPolyline());
}
}
}
any help is more than apreciated!!!
thank´s in forward!