Hey Thomas,
You're problem is that mapContainer doesn't actually exist until the
currentState=state0 and you're trying to add the map to it, when you
run into errors like this try to point out the line number in the
error, my guess is mapContainer.addChild(googleMap) is the line in
question. I don't know why you're using states so it's hard for me to
give you a solution but I think what you want to do is create the
mapContainer in advance keep a handle on it and add it as a child of
the panel in the state change, unfortunately there's no clean good way
to do this in MXML I'd suggest moving this
<mx:Box width="600" height="100%">
<mx:UIComponent id="mapContainer"
width="100%"
height="100%"/>
</mx:Box>
into it's own mxml file then lets say you called that
MapContainer.mxml
then in your script block of the original component make an instance
of that thing in creationComplete (ideally you should do this in an
overridden createChildren, but this will work) so at the top of the
script block
private var mapContainer:MapContainer;
then in creationComplete handler method called init() before doing the
addChild on mapContainer
mapContainer= new <apContainer();
and in the state mxml
<mx:State name="state0">
<mx:AddChild relativeTo="{pnlMain}" position="lastChild"
target="{mapContainer}"/>
</mx:State>
naming the property target is a bit counter-intuitive to me but that's
what you want
Shaun
On Mar 18, 5:10 am, Thomas <[email protected]> wrote:
> Hi, I wrote a little Flex app utilizing Google Maps in one part and it
> works fine. Now the app became a little bit more complex so I decided
> to use states. Here I am running into error #1009. I tried to minimize
> the code and the following is the outcome. With this code I still get
> the error. Could you help me out here, because I don't understand the
> error message of the Flash viewer.
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
> layout="absolute"
> verticalAlign="middle"
> backgroundColor="white"
> creationComplete="init();">
>
> <mx:Panel id="pnlMain" width="885" height="750"
> layout="absolute" />
>
> <mx:states>
> <mx:State name="state0">
> <mx:AddChild relativeTo="{pnlMain}" position="lastChild">
> <mx:Box width="600" height="100%">
> <mx:UIComponent id="mapContainer"
> width="100%"
> height="100%"/>
> </mx:Box>
> </mx:AddChild>
> </mx:State>
> </mx:states>
>
> <mx:Script>
> <![CDATA[
>
> import com.google.maps.*;
> import com.google.maps.controls.*;
> import com.google.maps.interfaces.*;
> import com.google.maps.overlays.*;
> import com.google.maps.services.*;
> import com.google.maps.styles.*;
>
> private var googleMap:Map;
>
> private function init():void {
> googleMap = new Map();
> googleMap.key = "your Key"
> googleMap.addEventListener(MapEvent.MAP_READY,
> googleMap_mapReady);
> googleMap.setSize(new Point(mapContainer.width,
> mapContainer.height));
> googleMap.addControl(new ZoomControl());
> googleMap.addControl(new MapTypeControl());
> googleMap.addControl(new OverviewMapControl());
> googleMap.addControl(new PositionControl());
>
> mapContainer.addChild(googleMap);
> }
>
> private function googleMap_mapReady(event:Event):void
> {
> googleMap.removeMapType(MapType.NORMAL_MAP_TYPE);
> googleMap.removeMapType(MapType.HYBRID_MAP_TYPE);
> //
> MapType,MapType.NORMAL_MAP_TYPE, .SATELLITE_MAP_TYPE, .PHYSICAL_MAP_TYPE,
> HYBRID_MAP_TYPE
> googleMap.setCenter(new LatLng(76, -42.258911), 3,
> MapType.PHYSICAL_MAP_TYPE);
> googleMap.enableScrollWheelZoom();
> googleMap.enableContinuousZoom();
> googleMap.savePosition();
> }
>
> ]]>
> </mx:Script>
> </mx:Application>
>
> Thank you,
> Thomas
--
You received this message because you are subscribed to the Google Groups
"Google Maps API For Flash" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-api-for-flash?hl=en.