kshelton360
11-09-2009, 01:35 PM
Getting a compile error. Line 52. I have gone over the code with a fine tooth comb and I cannot figure it out. It's driving me crazy! Any help would greatly be appreciated.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="100%" height="100%" viewSourceURL="srcview/index.html">
<mx:Style source="road.css"/>
<mx:Component id="HTMLRenderer">
<mx:Text width="100%" htmlText="{listData.label}"/>
</mx:Component>
<mx:ApplicationControlBar width="95%" height="35">
<mx:HBox width="100%">
<mx:Label text="Enter address:" />
<mx:TextInput
id="address"
text=" "
dropShadowColor="0x000000"
enter="doGeocode(event);" />
<mx:Button
id="submitButton" label="Search"
click="doGeocode(event);" />
<mx:Spacer width="100%"/>
<mx:Label text="Directions Travel Mode:"/>
<mx:RadioButtonGroup id="directionsOptions"/>
<mx:RadioButton label="Driving" groupName="directionsOptions" value="drive" selected="true"/>
<mx:RadioButton label="Walking" groupName="directionsOptions" value="walk"/>
</mx:HBox>
</mx:ApplicationControlBar>
<mx:Panel width="95%" height="80%" title="Instant Maps/Directions">
<mx:HDividedBox width="100%" height="100%">
<mx:VBox width="100%" height="100%">
<mx:HBox>
<mx:Label
text="From: "
width="70"/>
<mx:TextInput
id="from"
text=" "
width="100%"/>
</mx:HBox>
<mx:HBox>
<mx:Label
text="To: "
width="70"/>
<mx:TextInput
id="to"
text=" "
width="100%"/>
</mx:HBox>
<mx:Button
label="Get Directions"
click="processForm(event);"/>
<mx:HRule
width="100%"/>
<mx:Text
id="directionsSummary"
width="100%"/>
<mx:DataGrid
id="directionsGrid"
dataProvider="{directionsSteps}"
width="100%"
height="100%"
sortableColumns="false" itemClick="onGridClick(event)">
<mx:columns>
<mx:Array>
<mx:DataGridColumn headerText="Description" dataField="descriptionHtml"
itemRenderer="{HTMLRenderer}"/>
<mx:DataGridColumn headerText="Distance" dataField="distanceHtml"
width="120" itemRenderer="{HTMLRenderer}"/>
</mx:Array>
</mx:columns>
</mx:DataGrid>
<mx:Text
id="directionsCopyright"
width="100%"/>
</mx:VBox>
<mx:UIComponent
id="mapContainer"
initialize="startMap(event);"
resize="resizeMap(event)"
width="100%"
height="100%"/>
</mx:HDividedBox>
</mx:Panel>
<mx:Script>
<![CDATA[
import com.google.maps.overlays.Marker;
import flash.events.Event;
import com.google.maps.MapEvent;
import com.google.maps.Map;
import com.google.maps.MapType;
import com.google.maps.LatLng;
import com.google.maps.InfoWindowOptions;
import com.google.maps.LatLngBounds;
import com.google.maps.overlays.Polyline;
import com.google.maps.interfaces.IPolyline;
import com.google.maps.services.*;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
//geocode imports
import com.google.maps.services.ClientGeocoderOptions;
import com.google.maps.services.ClientGeocoder;
import com.google.maps.services.GeocodingEvent;
import com.google.maps.MapMouseEvent;
private var map:Map;
[Bindable] public var directionsSteps:ArrayCollection = new ArrayCollection();
public function startMap(event:Event):void {
map = new Map();
map.key = "ABQIAAAA7QUChpcnvnmXxsjC7s1fCxQGj0PqsCtxKvarsoS-iqLdqZSKfxTd7Xf-2rEc_PC9o8IsJde80Wnj4g";
map.addEventListener(MapEvent.MAP_READY, onMapReady);
mapContainer.addChild(map);
}
public function resizeMap(event:Event):void {
map.setSize(new Point(mapContainer.width, mapContainer.height));
}
private function onMapReady(event:MapEvent):void {
map.setCenter(new LatLng(41.0789,-81.5157), 14, MapType.NORMAL_MAP_TYPE);
}
private function processForm(event:Event):void {
trace(from.text + "" + to.text);
var directions:Directions = new Directions();
directions.addEventListener(DirectionsEvent.DIRECT IONS_SUCCESS,onDirectionsSuccess);
directions.addEventListener(DirectionsEvent.DIRECT IONS_FAILURE,onDirectionsFail);
directions.load(" from: " + from.text + " to: " + to.text);
}
if(directionsOptions.selectedValue == "drive")
{
var options:DirectionsOptions = new DirectionsOptions({
language: 'en',
countryCode: 'US',
travelMode: DirectionsOptions.TRAVEL_MODE_DRIVING });
}
else(directionsOptions.selectedValue == "walk")
{
var options:DirectionsOptions = new DirectionsOptions({
language: 'en',
countryCode: 'US',
travelMode: DirectionsOptions.TRAVEL_MODE_WALKING });
}
private function onDirectionsFail(event:DirectionsEvent):void
{
Alert.show("Status:" + event.directions.status);
}
private function onDirectionsSuccess(event:DirectionsEvent):void
{
map.clearOverlays();
directionsSteps.removeAll();
var directions:Directions = event.directions;
var directionsPolyline:IPolyline = directions.createPolyline();
map.addOverlay(directionsPolyline);
var directionsBounds:LatLngBounds = directionsPolyline.getLatLngBounds();
map.setCenter(directionsBounds.getCenter());
map.setZoom(map.getBoundsZoomLevel(directionsBound s));
var startLatLng:LatLng = directions.getRoute(0).getStep(0).latLng;
var endLatLng:LatLng = directions.getRoute(directions.numRoutes-1).endLatLng;
map.addOverlay(new Marker(startLatLng));
map.addOverlay(new Marker(endLatLng));
for (var r:Number = 0 ; r < directions.numRoutes; r++){
var route:Route = directions.getRoute(r);
for (var s:Number = 0 ; s < route.numSteps; s++ ){
var step:Step = route.getStep(s);
directionsSteps.addItem(step);
}
}
}
private function onGridClick(event:Event):void {
var latLng:LatLng = directionsGrid.selectedItem.latLng;
var opts:InfoWindowOptions = new InfoWindowOptions();
opts.contentHTML = directionsGrid.selectedItem.descriptionHtml;
map.openInfoWindow(latLng, opts);
}
// geocode
private function doGeocode(event:Event):void {
// Geocoding example
var geocoder:ClientGeocoder = new ClientGeocoder();
geocoder.addEventListener(
GeocodingEvent.GEOCODING_SUCCESS,
function(event:GeocodingEvent):void {
var placemarks:Array = event.response.placemarks;
if (placemarks.length > 0) {
map.setCenter(placemarks[0].point);
var marker:Marker = new Marker(placemarks[0].point);
marker.addEventListener(MapMouseEvent.CLICK, function (event:MapMouseEvent):void {
marker.openInfoWindow(new InfoWindowOptions({content: placemarks[0].address}));
});
map.addOverlay(marker);
}
});
geocoder.addEventListener(
GeocodingEvent.GEOCODING_FAILURE,
function(event:GeocodingEvent):void {
Alert.show("Geocoding failed");
trace(event);
trace(event.status);
});
geocoder.geocode(address.text);
}
]]>
</mx:Script>
</mx:Application>
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="100%" height="100%" viewSourceURL="srcview/index.html">
<mx:Style source="road.css"/>
<mx:Component id="HTMLRenderer">
<mx:Text width="100%" htmlText="{listData.label}"/>
</mx:Component>
<mx:ApplicationControlBar width="95%" height="35">
<mx:HBox width="100%">
<mx:Label text="Enter address:" />
<mx:TextInput
id="address"
text=" "
dropShadowColor="0x000000"
enter="doGeocode(event);" />
<mx:Button
id="submitButton" label="Search"
click="doGeocode(event);" />
<mx:Spacer width="100%"/>
<mx:Label text="Directions Travel Mode:"/>
<mx:RadioButtonGroup id="directionsOptions"/>
<mx:RadioButton label="Driving" groupName="directionsOptions" value="drive" selected="true"/>
<mx:RadioButton label="Walking" groupName="directionsOptions" value="walk"/>
</mx:HBox>
</mx:ApplicationControlBar>
<mx:Panel width="95%" height="80%" title="Instant Maps/Directions">
<mx:HDividedBox width="100%" height="100%">
<mx:VBox width="100%" height="100%">
<mx:HBox>
<mx:Label
text="From: "
width="70"/>
<mx:TextInput
id="from"
text=" "
width="100%"/>
</mx:HBox>
<mx:HBox>
<mx:Label
text="To: "
width="70"/>
<mx:TextInput
id="to"
text=" "
width="100%"/>
</mx:HBox>
<mx:Button
label="Get Directions"
click="processForm(event);"/>
<mx:HRule
width="100%"/>
<mx:Text
id="directionsSummary"
width="100%"/>
<mx:DataGrid
id="directionsGrid"
dataProvider="{directionsSteps}"
width="100%"
height="100%"
sortableColumns="false" itemClick="onGridClick(event)">
<mx:columns>
<mx:Array>
<mx:DataGridColumn headerText="Description" dataField="descriptionHtml"
itemRenderer="{HTMLRenderer}"/>
<mx:DataGridColumn headerText="Distance" dataField="distanceHtml"
width="120" itemRenderer="{HTMLRenderer}"/>
</mx:Array>
</mx:columns>
</mx:DataGrid>
<mx:Text
id="directionsCopyright"
width="100%"/>
</mx:VBox>
<mx:UIComponent
id="mapContainer"
initialize="startMap(event);"
resize="resizeMap(event)"
width="100%"
height="100%"/>
</mx:HDividedBox>
</mx:Panel>
<mx:Script>
<![CDATA[
import com.google.maps.overlays.Marker;
import flash.events.Event;
import com.google.maps.MapEvent;
import com.google.maps.Map;
import com.google.maps.MapType;
import com.google.maps.LatLng;
import com.google.maps.InfoWindowOptions;
import com.google.maps.LatLngBounds;
import com.google.maps.overlays.Polyline;
import com.google.maps.interfaces.IPolyline;
import com.google.maps.services.*;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
//geocode imports
import com.google.maps.services.ClientGeocoderOptions;
import com.google.maps.services.ClientGeocoder;
import com.google.maps.services.GeocodingEvent;
import com.google.maps.MapMouseEvent;
private var map:Map;
[Bindable] public var directionsSteps:ArrayCollection = new ArrayCollection();
public function startMap(event:Event):void {
map = new Map();
map.key = "ABQIAAAA7QUChpcnvnmXxsjC7s1fCxQGj0PqsCtxKvarsoS-iqLdqZSKfxTd7Xf-2rEc_PC9o8IsJde80Wnj4g";
map.addEventListener(MapEvent.MAP_READY, onMapReady);
mapContainer.addChild(map);
}
public function resizeMap(event:Event):void {
map.setSize(new Point(mapContainer.width, mapContainer.height));
}
private function onMapReady(event:MapEvent):void {
map.setCenter(new LatLng(41.0789,-81.5157), 14, MapType.NORMAL_MAP_TYPE);
}
private function processForm(event:Event):void {
trace(from.text + "" + to.text);
var directions:Directions = new Directions();
directions.addEventListener(DirectionsEvent.DIRECT IONS_SUCCESS,onDirectionsSuccess);
directions.addEventListener(DirectionsEvent.DIRECT IONS_FAILURE,onDirectionsFail);
directions.load(" from: " + from.text + " to: " + to.text);
}
if(directionsOptions.selectedValue == "drive")
{
var options:DirectionsOptions = new DirectionsOptions({
language: 'en',
countryCode: 'US',
travelMode: DirectionsOptions.TRAVEL_MODE_DRIVING });
}
else(directionsOptions.selectedValue == "walk")
{
var options:DirectionsOptions = new DirectionsOptions({
language: 'en',
countryCode: 'US',
travelMode: DirectionsOptions.TRAVEL_MODE_WALKING });
}
private function onDirectionsFail(event:DirectionsEvent):void
{
Alert.show("Status:" + event.directions.status);
}
private function onDirectionsSuccess(event:DirectionsEvent):void
{
map.clearOverlays();
directionsSteps.removeAll();
var directions:Directions = event.directions;
var directionsPolyline:IPolyline = directions.createPolyline();
map.addOverlay(directionsPolyline);
var directionsBounds:LatLngBounds = directionsPolyline.getLatLngBounds();
map.setCenter(directionsBounds.getCenter());
map.setZoom(map.getBoundsZoomLevel(directionsBound s));
var startLatLng:LatLng = directions.getRoute(0).getStep(0).latLng;
var endLatLng:LatLng = directions.getRoute(directions.numRoutes-1).endLatLng;
map.addOverlay(new Marker(startLatLng));
map.addOverlay(new Marker(endLatLng));
for (var r:Number = 0 ; r < directions.numRoutes; r++){
var route:Route = directions.getRoute(r);
for (var s:Number = 0 ; s < route.numSteps; s++ ){
var step:Step = route.getStep(s);
directionsSteps.addItem(step);
}
}
}
private function onGridClick(event:Event):void {
var latLng:LatLng = directionsGrid.selectedItem.latLng;
var opts:InfoWindowOptions = new InfoWindowOptions();
opts.contentHTML = directionsGrid.selectedItem.descriptionHtml;
map.openInfoWindow(latLng, opts);
}
// geocode
private function doGeocode(event:Event):void {
// Geocoding example
var geocoder:ClientGeocoder = new ClientGeocoder();
geocoder.addEventListener(
GeocodingEvent.GEOCODING_SUCCESS,
function(event:GeocodingEvent):void {
var placemarks:Array = event.response.placemarks;
if (placemarks.length > 0) {
map.setCenter(placemarks[0].point);
var marker:Marker = new Marker(placemarks[0].point);
marker.addEventListener(MapMouseEvent.CLICK, function (event:MapMouseEvent):void {
marker.openInfoWindow(new InfoWindowOptions({content: placemarks[0].address}));
});
map.addOverlay(marker);
}
});
geocoder.addEventListener(
GeocodingEvent.GEOCODING_FAILURE,
function(event:GeocodingEvent):void {
Alert.show("Geocoding failed");
trace(event);
trace(event.status);
});
geocoder.geocode(address.text);
}
]]>
</mx:Script>
</mx:Application>