5 Replies Latest reply on Nov 16, 2009 7:20 AM by nittanylion88

    1046: Type was not found or was not a compile-time constant: MapEvent. Help Please!

    nittanylion88

      Hi All,

       

      I am new to the Flex world and have already recieved some great help from the members here.  Pasted below is the code I am getting an error with. It only started happening when I tried to use the UMap plugin for Flex. The line that is throwing the error is in red.

       

      Thanks in advance!

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
        creationComplete="onStartup()" width="660" height="400"
        horizontalScrollPolicy="off" verticalScrollPolicy="off">

       

      <mx:Script>
      <![CDATA[
      import com.afcomponents.umap.overlays.Marker;
      import com.afcomponents.umap.types.LatLng;
      import com.afcomponents.umap.gui.*;
      import com.afcomponents.umap.events.MapEvent;
      import com.afcomponents.umap.core.UMap;
      import mx.core.UIComponent;
      import mx.controls.Image;
      import mx.rpc.events.ResultEvent;

       

      private const FLICKR_KEY:String = '9fa38e576d3976a7b3f8023207eec62a';

       

      private var images:Array = [];
      private var imageItems:Array = [];

       

      private var map:UMap = null;

       

      private function createFlickrURL( ) : String {
        var query:String = 'http://api.flickr.com/services/rest/?api_key='+FLICKR_KEY;
        query += '&method=flickr.photos.search&extras=geo';
        query += '&text='+parameters.text;
        query += '&lat='+parameters.lat;
        query += '&lon='+parameters.lon;
        query += '&radius=30';
        query += '&per_page=100&page=1&sort=date-posted-desc';
        return query;
      }

       

      private function onStartup() : void {
        flickrSearch.url = createFlickrURL();
        flickrSearch.send();
        for( var imgItem:int = 0; imgItem < ( hbPictures.width - 30 ) / 80; imgItem++ ) {
          var newImage:Image = new Image();
          newImage.data = null;
          newImage.width = 75;
          newImage.height = 75;
          newImage.addEventListener(MouseEvent.CLICK,onImageClick);
          imageItems.push( newImage );
          hbPictures.addChild( newImage );
        }
      }

       

      private function createMap() : void {
        map = new UMap();

       

        var uic:UIComponent = new UIComponent();
        uic.setStyle( 'top', 0 );
        uic.setStyle( 'left', 0 );
        uic.width = mapArea.width;
        uic.height = mapArea.height;
        mapArea.addChild( uic );

       

        map.setSize( mapArea.width, mapArea.height );
        map.addEventListener(MapEvent.READY, onMapReady);
        uic.addChild( map ); 
      }    

       

      private function onMapReady( event:MapEvent ) : void {
        map.setZoom( 12 );
        centerMap();
      }

       

      private function centerMap() : void {
        var lat:Number = Number( imgSelected.data.latitude );
        var lng:Number = Number( imgSelected.data.longitude );
        map.setCenter( new LatLng( lat, lng ) );
        var m:Marker = new Marker( { position:new LatLng( lat, lng ) } );
        map.addOverlay( m );
      }

       

      private function onImageClick( event:Event ) : void {
        var clkImg:Image = event.currentTarget as Image;
        imgSelected.data = clkImg.data;
        imgSelected.source = clkImg.data.bigSource;
        imgTitle.text = clkImg.data.title;
        if ( mapArea.getChildren().length == 0 ) {
          createMap();
        } else {
          centerMap();
        }
      }

       

      private function setPictures() : void {
        for each( var ii:Image in imageItems ) {
          var imgIndex:int = int( Math.random() * images.length );
          ii.data = images[ imgIndex ];
          ii.source = images[ imgIndex ].source;
        }
      }

       

      private function onFlickrResult( event:ResultEvent ) : void {
        for each( var photo:XML in event.result..photo ) {
          var smallPhotoUrl:String = 'http://static.flickr.com/'+photo.@server+'/'+photo.@id+'_'+photo.@secret+'_s.jpg';
          var bigPhotoUrl:String = 'http://static.flickr.com/'+photo.@server+'/'+photo.@id+'_'+photo.@secret+'.jpg';
          images.push( {
            source:smallPhotoUrl,
            bigSource:bigPhotoUrl,
            title:photo.@title,
              latitude:photo.@latitude,
              longitude:photo.@longitude
            } );
        }
        setPictures();
      }
      ]]>
      </mx:Script>

       

      <mx:HTTPService id="flickrSearch" resultFormat="e4x" result="onFlickrResult(event)" />

       

      <mx:HBox id="hbPictures" cornerRadius="15" width="660" height="100" borderColor="#00FF00"
        borderThickness="3" borderStyle="solid" backgroundColor="#CCFFCC"
        paddingBottom="10" paddingTop="10" paddingLeft="10" paddingRight="10" horizontalGap="5"
        horizontalScrollPolicy="off" verticalScrollPolicy="off">
      </mx:HBox>

       

      <mx:HBox id="hbDetail" top="110" cornerRadius="15" width="660" height="290" borderColor="#00FF00"
        borderThickness="3" borderStyle="solid" backgroundColor="#CCFFCC"
        paddingBottom="10" paddingTop="10" paddingLeft="10" paddingRight="10" horizontalGap="5"
        horizontalScrollPolicy="off" verticalScrollPolicy="off">
        <mx:Image id="imgSelected" width="270" height="270" horizontalAlign="center" verticalAlign="middle" />
        <mx:VBox width="100%" height="100%" horizontalScrollPolicy="off" verticalScrollPolicy="off">
          <mx:Label id="imgTitle" fontWeight="bold" fontSize="14" />
          <mx:Canvas id="mapArea" height="230" width="360" horizontalScrollPolicy="off"
             verticalScrollPolicy="off" clipContent="true" />
        </mx:VBox>
        </mx:HBox>

       

        </mx:Application>