Solved

Continuing writing ActionScript Coding

Posted on 2011-09-14
8
398 Views
Last Modified: 2013-11-11
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

0
Comment
Question by:fool5683
  • 3
  • 3
8 Comments
 
LVL 29

Expert Comment

by:dgofman
ID: 36552955
Are you still waiting this answer?
0
 

Author Comment

by:fool5683
ID: 36553039
yes
0
 
LVL 29

Expert Comment

by:dgofman
ID: 36553044
PLease can you attach your FLA file (don't forget to save as CS4) I will update your logic
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:fool5683
ID: 36553091
Ok here it is.
MapSimple2.fla
0
 
LVL 29

Accepted Solution

by:
dgofman earned 500 total points
ID: 36553126
Ok, I finish your task for CS
I also includ logic to remember last user entry.
You can simple test by enter valud into fields and click Search, when you will get a result close app and run again. Check you combo fields you should get last destinations
MapSimple2.fla
0
 

Author Closing Comment

by:fool5683
ID: 36553833
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 !!!!!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Read about why website design really matters in today's demanding market.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now