2012-01-11 7 views
0

StyledMapTypeのAS3でのGoogleマップのAPIに、StyledMapTypeの

var styles:Array = [ 
new MapTypeStyle(
MapTypeStyleFeatureType.ALL, 
MapTypeStyleElementType.ALL, 
[ 
MapTypeStyleRule.visibility("on"), 
MapTypeStyleRule.hue(0xff0000), 
MapTypeStyleRule.saturation(100), 
MapTypeStyleRule.lightness(-50), 
MapTypeStyleRule.gamma(1.0) 
] 
) 
]; 

var options:StyledMapTypeOptions = new StyledMapTypeOptions({ 
name: 'Styled map', 
alt: 'Style', 
minResolution: 2, 
maxResolution: 12 
}); 

var styledMapType:StyledMapType = new StyledMapType(styles, options); 

をインスタンス化する際に、私はnull参照の例外を持つ私はこのエラーを取得しています:

TypeError: Error #1009: Cannot access a property or method of a null object reference. 
    at com.google.maps::StyledMapType() 
    at com::Main/init() 
    at com::Main() 

しかし、ときに私は、この行を省略:

var styledMapType:StyledMapType = new StyledMapType(styles, options);

プログラムが実行されます。私を助けてください。私は何時間も解決策と問題を見つけようとしています。あなたがMAP_READYにイベントリスナーを登録し、リスナーにこのコードを配置する必要があり

おかげ

答えて

0

。あなたのGoogleマップオブジェクトがまだ完全にインスタンス化されていないため、エラーが発生している可能性があります。

public function somefunction(): void 
{ 
    yourGoogleMapobject.addEventListener(MapEvent.MAP_READY, onMapReady); 
} 

private function onMapReady(event:Event):void 
{ 
    var styles:Array = [ 
    new MapTypeStyle(
    MapTypeStyleFeatureType.ALL, 
    MapTypeStyleElementType.ALL, 
    [ 
    MapTypeStyleRule.visibility("on"), 
    MapTypeStyleRule.hue(0xff0000), 
    MapTypeStyleRule.saturation(100), 
    MapTypeStyleRule.lightness(-50), 
    MapTypeStyleRule.gamma(1.0) 
    ] 
    ) 
    ]; 

    var options:StyledMapTypeOptions = new StyledMapTypeOptions({ 
    name: 'Styled map', 
    alt: 'Style', 
    minResolution: 2, 
    maxResolution: 12 
    }); 

    var styledMapType:StyledMapType = new StyledMapType(styles, options); 
}