Link to home
Start Free TrialLog in
Avatar of fool5683
fool5683Flag for United States of America

asked on

Continuing writing ActionScript Coding

Utilizing the following code,
I would like the user to be able to select locations from the following comboxes:
startAdd_cmb, endAdd_cmb
Then have the values transmitted to the startfield and the endfield so that they can become the starting and ending locations.

The combo boxes were created in Flash with the data.

Please advise
import com.google.maps.InfoWindowOptions;
import com.google.maps.LatLng;
import com.google.maps.LatLngBounds;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapMoveEvent;
import com.google.maps.MapType;
import com.google.maps.interfaces.IPolyline;
import com.google.maps.overlays.Marker;
import com.google.maps.overlays.MarkerOptions;
import com.google.maps.services.*;

var dir:Directions;
var polyline:IPolyline;
var map:Map;
function setupMap()
{
	var holder:Sprite = new Sprite();
	var startField:TextField = createNavTextField(10);
	holder.addChild(startField);
	
	var endField:TextField = createNavTextField(startField.x + startField.width + 10);
	holder.addChild(endField);
	
	var search:SimpleButton = new SimpleButton();
	search.upState = createButtonStateState(0xcccccc);
	search.overState = createButtonStateState(0xc6c6c6);
	search.downState = createButtonStateState(0x999999);
	search.hitTestState = createButtonStateState(0x999999);
	search.useHandCursor = true;
	search.addEventListener(MouseEvent.CLICK, function(event:MouseEvent):void{
		if(dir == null){
			dir = new Directions();
		}else{
			dir.removeEventListener(DirectionsEvent.DIRECTIONS_SUCCESS,onDirectionsLoaded);
		}
		dir.addEventListener(DirectionsEvent.DIRECTIONS_SUCCESS,onDirectionsLoaded);
		dir.load(startField.text + " to " + endField.text);
	});
	
	var format:TextFormat = new TextFormat(); 
	format.align = TextFormatAlign.CENTER; 
	var label:TextField = new TextField();
	label.defaultTextFormat = format; 
	label.selectable = false;
	label.mouseEnabled = false;
	label.text = "Calculate";
	label.width = search.width;

	var sprite:Sprite = new Sprite();
	sprite.addChild(search);
	sprite.addChild(label);
	sprite.x = endField.x + endField.width + 10;
	sprite.y = endField.y;

	holder.addChild(sprite);

	map = new Map();
	map.sensor ="false";
	map.key ="ABQIAAAAjf2cvxDuc5J1E9CrJXmy9RQrAB2acdB4QgEQtVMeGDLCPkNwtRR8XAwx0MS9MI4RYmgwJ-jCIN9QaQ";
	map.setSize(new Point(400,400));
	map.x = startField.x;
	map.y = startField.y + startField.height + 5;
	holder.addChild(map);

	addChild(holder);
}
setupMap();

function createNavTextField(x:uint):TextField{
	var textField:TextField = new TextField();
	textField.autoSize = TextFieldAutoSize.NONE;
	textField.type = TextFieldType.INPUT;
	textField.multiline = false;
	textField.tabEnabled = true;
	textField.wordWrap = false;
	textField.border = true;
	textField.background = true;
	textField.x = x;
	textField.y = 10
	textField.width = 195;
	textField.height = 22;
	return textField;
}

function createButtonStateState(color:Number):Sprite {
	var sprite:Sprite = new Sprite;
	sprite.graphics.lineStyle(2, 0x000000);
	sprite.graphics.beginFill(color);
	sprite.graphics.drawRoundRect(0, 0, 80, 22, 10);
	sprite.graphics.endFill();
	return sprite;
}

function onDirectionsLoaded(event:DirectionsEvent):void
{
	var ONE_METER:Number = 0.000621371192; // Miles 
	var returnedDirection:Directions = event.directions as Directions;
	
	var startLatLng:LatLng = returnedDirection.getRoute(0).getStep(0).latLng;
	var endLatLng:LatLng = returnedDirection.getRoute(returnedDirection.numRoutes - 1).endLatLng;
	var returnedDistance = Number(returnedDirection.distance * ONE_METER).toFixed(1);
	var returnedTime = Math.round(returnedDirection.duration / 60) + 30;
	returnedDistance_txt.text = "The total distance to your destination is " +  returnedDistance + " Miles";
	returnedTime_txt.text = "You should allow at least " +  returnedTime + " Minutes to arrive and find adequate parking due to typical traffic flow";
	
	
	
	polyline = returnedDirection.createPolyline();
	
	// Remove everything from map and add back the markers and polyline 
	map.clearOverlays();
	map.addOverlay(polyline);
	map.addOverlay(new Marker(startLatLng));
	map.addOverlay(new Marker(endLatLng));
	map.setCenter(returnedDirection.bounds.getCenter(), map.getBoundsZoomLevel(returnedDirection.bounds));
	
	trace("Distance: " + Number(returnedDirection.distance * ONE_METER).toFixed(1) + " mi, " + 
		Math.round(returnedDirection.duration / 60) +  " mins");

	
	}

Open in new window

Avatar of dgofman
dgofman
Flag of United States of America image

Are you still waiting this answer?
Avatar of fool5683

ASKER

yes
PLease can you attach your FLA file (don't forget to save as CS4) I will update your logic
Ok here it is.
MapSimple2.fla
ASKER CERTIFIED SOLUTION
Avatar of dgofman
dgofman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This was awesome!!!! I made one very small adjustments:
"1.import fl.data.DataProvider;"
I imported the DataProvider along with the
" import fl.data.SimpleCollectionItem;"

Thanks for everything. You rock !!!!!