PDA

View Full Version : Help with google map in AS3


EddaRós
11-01-2008, 10:15 PM
I am making a website in flash and on one of the subpages there is a google map. I have managed to make a working google map, no problems there but I have another problem.

Right now I have my mainpage on the stage, when I press a btn then a movieclip opens which contains my subpage (with the google map) on the subpage there is another button that closes the subpage and brings you back to the stage.
This works fine, the google map shows without errors and everything is great but if I then want to look again at the google map then there is a problem.

I get this output:

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 flash_fla::google_overlay_7/flash_fla::frame2()

I understand this message that flash cannot show the map because it is allready running, or something like that.
So I ask, is there anyway that I can tell flash (any AS3 code) that I want to the map to be unloaded? Can I clean the AS memory so that when I enter the stage again it is like the map has never been shown before?

So this is the AS code on the stage:
stop();


//project button
btn_pro.buttonMode = true;
btn_pro.addEventListener(MouseEvent.MOUSE_OVER, btn_pro_active);
btn_pro.addEventListener(MouseEvent.MOUSE_OUT, btn_pro_nonactive);
function btn_pro_active(e:MouseEvent):void {
btn_pro.gotoAndStop(2);

}
function btn_pro_nonactive(e:MouseEvent):void {
btn_pro.gotoAndStop(1);
}


//video button
btn_vid.buttonMode = true;
btn_vid.addEventListener(MouseEvent.MOUSE_OVER, btn_vid_active);
btn_vid.addEventListener(MouseEvent.MOUSE_OUT, btn_vid_nonactive);
function btn_vid_active(e:MouseEvent):void {
btn_vid.gotoAndStop(2);

}
function btn_vid_nonactive(e:MouseEvent):void {
btn_vid.gotoAndStop(1);
}


//google button
btn_goo.buttonMode = true;
btn_goo.addEventListener(MouseEvent.MOUSE_OVER, btn_goo_active);
btn_goo.addEventListener(MouseEvent.MOUSE_OUT, btn_goo_nonactive);
btn_goo.addEventListener(MouseEvent.CLICK, btn_goo_over);
function btn_goo_active(e:MouseEvent):void {
btn_goo.gotoAndStop(2);

}
function btn_goo_nonactive(e:MouseEvent):void {
btn_goo.gotoAndStop(1);
}
function btn_goo_over(e:MouseEvent):void {
ov_goo.gotoAndStop(2);
}

//links button
btn_link.buttonMode = true;
btn_link.addEventListener(MouseEvent.MOUSE_OVER, btn_link_active);
btn_link.addEventListener(MouseEvent.MOUSE_OUT, btn_link_nonactive);
btn_link.addEventListener(MouseEvent.CLICK, btn_link_over);
function btn_link_active(e:MouseEvent):void {
btn_link.gotoAndStop(2);

}
function btn_link_nonactive(e:MouseEvent):void {
btn_link.gotoAndStop(1);
}
function btn_link_over(e:MouseEvent):void {
ov_link.gotoAndStop(2);
}

//galleri button
btn_gal.buttonMode = true;
btn_gal.addEventListener(MouseEvent.MOUSE_OVER, btn_gal_active);
btn_gal.addEventListener(MouseEvent.MOUSE_OUT, btn_gal_nonactive);
function btn_gal_active(e:MouseEvent):void {
btn_gal.gotoAndStop(2);

}
function btn_gal_nonactive(e:MouseEvent):void {
btn_gal.gotoAndStop(1);
}


//? button
btn_q.buttonMode = true;
btn_q.addEventListener(MouseEvent.MOUSE_OVER, btn_q_active);
btn_q.addEventListener(MouseEvent.MOUSE_OUT, btn_q_nonactive);
function btn_q_active(e:MouseEvent):void {
btn_q.gotoAndStop(2);

}
function btn_q_nonactive(e:MouseEvent):void {
btn_q.gotoAndStop(1);
}

And this is the AS code on the movie clip:
stop();

import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapMouseEvent;
import com.google.maps.MapType;
import com.google.maps.InfoWindowOptions;
import com.google.maps.controls.ZoomControl;
import com.google.maps.overlays.Marker;
import com.google.maps.overlays.MarkerOptions;
import com.google.maps.styles.FillStyle;
import com.google.maps.styles.StrokeStyle;



var map:Map = new Map();
map.key = "ABQIAAAAIy00-4LTQqNM-FGgJUrLvRRVpU4LQSkhsi11l9x9EOPX2dSAYRQ_QbNRxK-BWo9mQpp6WjNXEhhs9A";
map.setSize(new Point(400, 400));

map.addEventListener(MapEvent.MAP_READY, onMapReady);
this.addChild(map);




function onMapReady(event:Event):void {
map.setCenter(new LatLng (52.521717846742185, 13.41029405593872), 13, MapType.NORMAL_MAP_TYPE);
map.enableScrollWheelZoom();
map.enableContinuousZoom();
map.addControl(new ZoomControl());

var markerA:Marker = new Marker(
new LatLng (52.521717846742185, 13.41029405593872),
new MarkerOptions({
strokeStyle: new StrokeStyle({color: 0x987654}),
fillStyle: new FillStyle({color: 0xff4800, alpha: 0.5}),
radius: 8,
hasShadow: false
}));
var markerB:Marker = new Marker (
new LatLng(52.522670935314835, 13.402032852172852),
new MarkerOptions({
strokeStyle: new StrokeStyle({color: 0x987654}),
fillStyle: new FillStyle({color: 0xff4800, alpha: 0.5}),
radius: 8,
hasShadow: false
}));
var markerC:Marker = new Marker (
new LatLng (52.51982466427605, 13.387935161590576),
new MarkerOptions({
strokeStyle: new StrokeStyle({color: 0x987654}),
fillStyle: new FillStyle({color: 0xff4800, alpha: 0.5}),
radius: 8,
hasShadow: false
}));
var markerD:Marker = new Marker (
new LatLng (52.536351352328886, 13.407397270202637),
new MarkerOptions({
strokeStyle: new StrokeStyle({color: 0x987654}),
fillStyle: new FillStyle({color: 0xff4800, alpha: 0.5}),
radius: 8,
hasShadow: false
}));
var markerE:Marker = new Marker (
new LatLng (52.53466763785581, 13.403749465942383),
new MarkerOptions({
strokeStyle: new StrokeStyle({color: 0x987654}),
fillStyle: new FillStyle({color: 0xff4800, alpha: 0.5}),
radius: 8,
hasShadow: false
}));
var markerF:Marker = new Marker (
new LatLng (52.537617358669806, 13.396646976470947),
new MarkerOptions({
strokeStyle: new StrokeStyle({color: 0x987654}),
fillStyle: new FillStyle({color: 0xff4800, alpha: 0.5}),
radius: 8,
hasShadow: false
}));
var markerG:Marker = new Marker (
new LatLng (52.52492954210355, 13.368580341339111),
new MarkerOptions({
strokeStyle: new StrokeStyle({color: 0x987654}),
fillStyle: new FillStyle({color: 0xff4800, alpha: 0.5}),
radius: 8,
hasShadow: false
}));
var markerH:Marker = new Marker (
new LatLng (52.50953477032727, 13.376498222351074),
new MarkerOptions({
strokeStyle: new StrokeStyle({color: 0x987654}),
fillStyle: new FillStyle({color: 0xff4800, alpha: 0.5}),
radius: 8,
hasShadow: false
}));
var markerI:Marker = new Marker (
new LatLng (52.516377557048955, 13.378429412841797),
new MarkerOptions({
strokeStyle: new StrokeStyle({color: 0x987654}),
fillStyle: new FillStyle({color: 0xffff00, alpha: 0.5}),
radius: 8,
hasShadow: false
}));


markerA.addEventListener(MapMouseEvent.CLICK, function(event:MapMouseEvent):void {;
map.openInfoWindow(event.latLng, new InfoWindowOptions
({title: "Alexanderplatz", content: "Here we shot a lot of scenes"}));
});
map.addOverlay(markerA);

markerB.addEventListener(MapMouseEvent.CLICK, function(event:MapMouseEvent):void {;
map.openInfoWindow(event.latLng, new InfoWindowOptions
({tailAlign: InfoWindowOptions.ALIGN_CENTER, title: "Hackescher Markt", content: "Another great place"}));
});
map.addOverlay(markerB);

map.addOverlay(markerC);
map.addOverlay(markerD);
map.addOverlay(markerE);
map.addOverlay(markerF);
map.addOverlay(markerG);
map.addOverlay(markerH);
map.addOverlay(markerI);

var markerJ:Marker = new Marker(new LatLng (52.5173307614788, 13.395209312438965));

markerJ.addEventListener(MapMouseEvent.CLICK, function(e:Event):void {
var request:URLRequest = new URLRequest("pictures/markerJ.png");
var imageLoader:Loader = new Loader();
imageLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLETE, function(event:Event):void {
var width:Number = imageLoader.width;
var height:Number = imageLoader.height;
var options2:InfoWindowOptions = new InfoWindowOptions({

hasShadow: false,
customContent: imageLoader,
customOffset: new Point(0,100),
customCloseRect: new Rectangle(50, 50, 20, 150)});
markerJ.openInfoWindow(options2);
});
imageLoader.load(request);
});
this.map.addOverlay(markerJ);
}


btn_x.buttonMode = true;
btn_x.addEventListener(MouseEvent.CLICK, back);
function back(e:MouseEvent):void {
gotoAndStop(1);
this.removeChild(map);


};


(right now I am also trying out different way's to put markers on the google map, both of them work.)

So is there anyone that can help me?