1
votes

I'm trying to move to another frame by clicking a movieclip. I have checked the frame name, etc, but it always gets an error like this whenever I tried to click my MovieClip. The application I made is combining google map with flash. So, when I click the movieclip, it should move to another frame containing google map.

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Stage@2675cf99 to flash.display.MovieClip.
at startMap/movetoMap()

This is my code :

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 before for any help provided....

2

2 Answers

1
votes

startMap is directly attached to the stage, and the stage class does not inherit from MovieClip.

You need to change MovieClip(this.parent).gotoAndStop("mymap"); to gotoAndStop("mymap");, or if you're adding startMap to the stage, instead of adding startMap with stage.addChild(startMapObj);, you should do this.addChild(startMapObj);.

0
votes

The scope of your moveToMap method is the startMap class itself (which I'm guessing is a MovieClip added to the root stage object). Therefore this.parent will resolve to the stage object, and by attempting to cast it to a different type (MovieClip) you're getting the type coercion error.

Is the mymap frame label actually on the root timeline? If you want to manipulate the root timeline you have to use Stage's root property (and cast it to MovieClip). So in your moveToMap function it'd look a bit like this:

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

(Note you'll only have access to the stage property if your DisplayObject is added to the display list).