<?xml version="1.0" encoding="utf-8"?>  
<!--
    Copyright (c) 2008 Yahoo! Inc.  All rights reserved.  
    The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
-->
<mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    layout="absolute" 
    creationComplete="handleCreationComplete();" 
    viewSourceURL="srcview/index.html">
      
    <mx:Panel title="Yahoo! Maps - Simple Flex Example" top="5" left="5" bottom="5" right="5">
        <!-- This is the map container, the YahooMap component extends Sprite, so you must add it to a UIComponent. -->
        <mx:UIComponent id="mapContainer" width="100%" height="100%"/>
    </mx:Panel>
    
    <mx:Script>  
        <![CDATA[
            import mx.events.ResizeEvent; 
            
            // import maps classes.
            import com.yahoo.maps.api.YahooMap; 
            import com.yahoo.maps.api.YahooMapEvent; 
            import com.yahoo.maps.api.core.location.Address; 
            import com.yahoo.maps.webservices.geocoder.GeocoderResult; 
            import com.yahoo.maps.webservices.geocoder.events.GeocoderEvent; 
            
            private var _yahooMap:YahooMap; 
            private var _address:Address; 
             
            private function handleCreationComplete():void  
            { 
                // this examples uses an application id passed into the app via FlashVars.
                // Get your own from the Yahoo! Developer Network @ http://developer.yahoo.com/wsregapp/
                var appid:String = Application.application.parameters.appid;
                
                // create a new YahooMap object.
                _yahooMap = new YahooMap(); 
                
                // list for the MAP_INITIALIZE event from YahooMap
                _yahooMap.addEventListener(YahooMapEvent.MAP_INITIALIZE, handleMapInitialize);
                
                // initialize the map, passing the app-id, width and height.
                _yahooMap.init(appid,mapContainer.width,mapContainer.height);
                 
                mapContainer.addChild(_yahooMap); 
                mapContainer.addEventListener(ResizeEvent.RESIZE, handleContainerResize); 
                 
                _yahooMap.addPanControl(); 
                _yahooMap.addZoomWidget(); 
                _yahooMap.addTypeWidget();  
            } 
             
            private function handleMapInitialize(event:YahooMapEvent):void  
            { 
                // creating a new address object, passing our address string as the single parameter. 
                _address = new Address("141 pike st. seattle,wa"); 
                 
                // listen for the GEOCODER_SUCCESS event dispatched when the data comes back from the webservice.
                _address.addEventListener(GeocoderEvent.GEOCODER_SUCCESS, handleGeocodeSuccess);
                
                // send the geocode request.
                _address.geocode(); 
            } 
             
            private function handleGeocodeSuccess(event:GeocoderEvent):void  
            { 
                // retrieve the first result returned by the geocoder. 
                var result:GeocoderResult = _address.geocoderResultSet.firstResult; 
                
                // then we'll get the zoom level and center latlon to position the map on. 
                _yahooMap.zoomLevel = result.zoomLevel; 
                _yahooMap.centerLatLon = result.latlon; 
                
            } 
             
            private function handleContainerResize(event:ResizeEvent):void {
                // set the size of the map based on its containers size.
                _yahooMap.setSize(mapContainer.width,mapContainer.height); 
            }
        ]]>  
    </mx:Script>  
</mx:Application>