2011-11-25 72 views
1

我试图通过单击一个影片剪辑移动到另一个帧。我检查了框架名称等,但每当我尝试点击我的MovieClip时,它总会得到像这样的错误。我做的应用是将谷歌地图和闪光灯结合在一起。所以,当我点击动画片段时,它应该移动到另一个包含谷歌地图的框架。actionscript 3.0类型强制错误

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::[email protected] to flash.display.MovieClip. 
at startMap/movetoMap() 

这是我的代码:

package { 

import flash.display.MovieClip; 
import flash.events.MouseEvent; 
import com.google.maps.*; 
import flash.geom.Point; 
import flash.events.Event; 
import com.google.maps.overlays.Marker; 
import com.google.maps.services.ClientGeocoder; 
import com.google.maps.services.GeocodingEvent; 

public class startMap extends MovieClip { 

    var gMap : Map = new Map(); 

    public function startMap() { 

     this.x = 700; 
     this.y = 150; 
     this.scaleX = 0.5; 
     this.scaleY = 0.5; 
     this.addEventListener(MouseEvent.CLICK, movetoMap); 
    } 

    function movetoMap (e : MouseEvent) 
    { 
//I think this is where the error took place... 
     MovieClip(this.parent).gotoAndStop("mymap"); // move to another frame 

        //the code below is for the next frame 
     //trace ("initiating map"); 
     /* 
     gMap.key = "ABQIAAAAkvJLDXCdl31EuFDEitKQ6hTDVs7mYo4hdRoqkWYrrPdtz_Eb9RRJP9mw3bPiboGSX4c0stQsYo4aPQ"; 
     gMap.sensor = "true"; 
     gMap.x = 100; 
     gMap.y = 50; 
     gMap.setSize(new Point(stage.width - 200, stage.height - 100)); 
     gMap.addEventListener(MapEvent.MAP_READY, prepareMap); 
     gMap.addEventListener(MapMouseEvent.CLICK, showPoint); 
     stage.addChild (gMap); 
     */ 
    } 
    /* 
    function prepareMap (e : Event) 
    { 
     doGeoCode ("Jakarta, Indonesia"); 
    } 

    function showPoint (e : MapMouseEvent) 
    { 
     var revGeoCode : ClientGeocoder = new ClientGeocoder(); 
     revGeoCode.addEventListener(GeocodingEvent.GEOCODING_SUCCESS, 
       function markPlace (e : GeocodingEvent) { 
        var place : Array = e.response.placemarks; 
        var marker : Marker = new Marker (place[0].point); 
        gMap.addOverlay(marker); 
        gMap.setZoom(8, true); 
        gMap.setCenter (marker.getLatLng()); 
        marker.addEventListener(MapMouseEvent.CLICK, 
          function showInfo(e : MapMouseEvent){ 
           gMap.openInfoWindow(marker.getLatLng(), 
            new InfoWindowOptions ({title:"Welcome to", content:place[0].address})); 
          }); 
       }); 
     revGeoCode.addEventListener(GeocodingEvent.GEOCODING_FAILURE, 
       function addFailure(e : GeocodingEvent){ 
        trace ('fail to geocode'); 
       }); 
     revGeoCode.reverseGeocode(e.latLng); 
    } 

    function doGeoCode (placeName : String) 
    { 
     var placeInfo : ClientGeocoder = new ClientGeocoder(); 
     placeInfo.addEventListener(GeocodingEvent.GEOCODING_SUCCESS, 
       function addInfo(e : GeocodingEvent){ 
        var place : Array = e.response.placemarks; 
        var mark : Marker = new Marker (place[0].point); 
        gMap.setCenter(mark.getLatLng()); 
        gMap.setZoom(8, true); 
        gMap.addOverlay(mark); 
        mark.addEventListener(MapMouseEvent.CLICK, 
          function setPlaceInfo (e : MapMouseEvent){ 
           gMap.openInfoWindow(place[0].point, 
            new InfoWindowOptions ({title:"Welcome to", content:place[0].address})); 
          }); 
       }); 
     placeInfo.addEventListener(GeocodingEvent.GEOCODING_FAILURE, 
       function addFailure(e : GeocodingEvent){ 
        trace ('fail to geocode'); 
       }); 
     placeInfo.geocode(placeName); 
    } 
    */ 
} 

}提供的任何帮助之前

THX ....

回答

1

startMap直接连接到舞台,而舞台类不从MovieClip继承。

您需要更改MovieClip(this.parent).gotoAndStop("mymap");gotoAndStop("mymap");,或者如果你添加startMap在舞台上,而不是用stage.addChild(startMapObj);添加startMap,你应该做的this.addChild(startMapObj);

+0

我试过this.addChild(myMapObj),但按钮没有出现在舞台上....如果我使用stage.addChild(myMapObj),按钮仍然出现我提到的错误 – Jason

+0

If你将它添加到舞台上,那么myMapObj的父级将成为舞台,并且不能将其发送到帧(它甚至没有帧)。如果你可以更好地解释你的动画是如何工作的,我们可以找到你的解决方案,你可能在舞台上增加了一些其他的东西,包括'this'和'myMapObj'。 – felipemaia

0

moveToMap方法的范围是startMap类本身(我猜测它是添加到根阶段对象的MovieClip)。因此,this.parent将解析为舞台对象,并试图将其转换为不同类型(MovieClip)时,您将得到类型强制错误。

mymap帧标签实际上是否在根时间轴上?如果你想操纵根时间轴,你必须使用Stage的root属性(并将其转换为MovieClip)。因此,在您moveToMap功能它会看起来有点像这样:

MovieClip(stage.root).gotoAndStop("mymap");

(请注意你,如果你DisplayObject被添加到显示列表中只能访问到stage属性)。