我試圖通過單擊一個影片剪輯移動到另一個幀。我檢查了框架名稱等,但每當我嘗試點擊我的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 ....
我試過this.addChild(myMapObj),但按鈕沒有出現在舞臺上....如果我使用stage.addChild(myMapObj),按鈕仍然出現我提到的錯誤 – Jason
If你將它添加到舞臺上,那麼myMapObj的父級將成爲舞臺,並且不能將其發送到幀(它甚至沒有幀)。如果你可以更好地解釋你的動畫是如何工作的,我們可以找到你的解決方案,你可能在舞臺上增加了一些其他的東西,包括'this'和'myMapObj'。 – felipemaia