Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Issue with Combo Box Data in Actionscript 3.0

Posted on 2011-09-22
12
Medium Priority
?
358 Views
Last Modified: 2012-05-12
Utilizing following code, I am attempting to have the user select a starting and end location which will be tthen be displayed on a Google map. The startadd_cmb combo box was populated via an array. However the code does not transfer the selected address from this combox to the appropriate field like the other combo box. 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.controls.PositionControl;
import com.google.maps.controls.ZoomControl;
import com.google.maps.controls.MapTypeControl;
import com.google.maps.interfaces.IPolyline;
import com.google.maps.overlays.Marker;
import com.google.maps.overlays.MarkerOptions;
import com.google.maps.services.*;
import fl.data.SimpleCollectionItem;
import fl.data.DataProvider;
import fl.events.ComponentEvent;

var items:Array = [ 
{label:"Jane Addams Elementary School", data:"10810 S Avenue H  Chicago, IL 60617"},
{label:"Louis A Agassiz Elementary School", data:"2851 N Seminary Ave  Chicago, IL 60657"},
{label:"Air Force Academy High School", data:"3630 S Wells St  Chicago, IL 60609"},
{label:"Albany Park Multicultural Academy", data:"4929 N Sawyer Ave  Chicago, IL 60625"},
{label:"Louisa May Alcott Elementary School", data:"2625 N Orchard St  Chicago, IL 60614"},
{label:"Alcott High School for the Humanities", data:"2957 N Hoyne Ave  Chicago, IL 60618"},
{label:"Ira F Aldridge Elementary School", data:"630 E 131st St  Chicago, IL 60827"},
{label:"ALOP Alternative Schools", data:"4655 S Dearborn St  Chicago, IL 60609"},
{label:"John P Altgeld Elementary School", data:"1340 W 71st St  Chicago, IL 60636"},
{label:"Ames Middle School", data:"1340 W 71st St  Chicago, IL 60636"},
{label:"Roald Amundsen High School", data:"1920 N Hamlin Ave  Chicago, IL 60647"},
{label:"Ariel Elementary Community Academy", data:"5110 N Damen Ave  Chicago, IL 60625"},
{label:"Phillip D Armour Elementary School", data:"1119 E 46th St  Chicago, IL 60653"},
{label:"George Armstrong International Studies ES", data:"950 W 33rd Pl  Chicago, IL 60608"},
{label:"Louis Armstrong Math & Science Elementary School", data:"2110 W Greenleaf Ave  Chicago, IL 60645"},
{label:"Ashburn Community Elementary School", data:"8300 S Saint Louis Ave  Chicago, IL 60652"},
{label:"Arthur R Ashe Elementary School", data:"8505 S Ingleside Ave  Chicago, IL 60619"},
{label:"Crispus Attucks Elementary School", data:"5055 S State St  Chicago, IL 60609"},
{label:"John J Audubon Elementary School", data:"3500 N Hoyne Ave  Chicago, IL 60618"},
{label:"Austin Polytechnical Academy High School", data:"231 N Pine Ave  Chicago, IL 60644"},
{label:"Avalon Park Elementary School", data:"8045 S Kenwood Ave  Chicago, IL 60619"},
{label:"Mariano Azuela Elementary School", data:"4707 W Marquette Rd  Chicago, IL 60629"},
{label:"Benjamin Banneker Elementary School", data:"6656 S Normal Blvd  Chicago, IL 60621"},
{label:"Alice L Barnard Computer Math & Science Ctr ES", data:"10354 S Charles St  Chicago, IL 60643"},
{label:"John Barry Elementary School", data:"2828 N Kilbourn Ave  Chicago, IL 60641"},
{label:"Clara Barton Elementary School", data:"7650 S Wolcott Ave  Chicago, IL 60620"},
{label:"Perkins Bass Elementary School", data:"1140 W 66th St  Chicago, IL 60621"},
{label:"Newton Bateman Elementary School", data:"4220 N Richmond St  Chicago, IL 60618"},
{label:"Daniel C Beard Elementary School", data:"6445 W Strong St  Chicago, IL 60656"},
{label:"Edward Beasley Elementary Magnet Academic Center", data:"5255 S State St  Chicago, IL 60609"},
{label:"Jean Baptiste Beaubien Elementary School", data:"5025 N Laramie Ave  Chicago, IL 60630"},
{label:"Ludwig Van Beethoven Elementary School", data:"25 W 47th St  Chicago, IL 60609"},
{label:"Jacob Beidler Elementary School", data:"3151 W Walnut St  Chicago, IL 60612"},
{label:"Hiram H Belding Elementary School", data:"4257 N Tripp Ave  Chicago, IL 60641"},
{label:"Alexander Graham Bell Elementary School", data:"3730 N Oakley Ave  Chicago, IL 60618"},
{label:"Belmont-Cragin Elementary School", data:"2456 N Mango Ave  Chicago, IL 60639"},
{label:"Frank I Bennett Elementary School", data:"10115 S Prairie Ave  Chicago, IL 60628"},
{label:"Best Practice High School", data:"2040 W Adams St  Chicago, IL 60612"},
{label:"Mary McLeod Bethune Elementary School", data:"3030 W Arthington St  Chicago, IL 60612"},
{label:"Robert A Black Magnet Elementary School", data:"9101 S Euclid Ave  Chicago, IL 60619"},
{label:"James G Blaine Elementary School", data:"1420 W Grace St  Chicago, IL 60613"},
{label:"Blair Early Childhood Center", data:"6751 W 63rd Pl  Chicago, IL 60638"},
{label:"William J Bogan High School", data:"3939 W 79th St  Chicago, IL 60652"},
{label:"Carrie Jacobs Bond Elementary School", data:"7050 S May St  Chicago, IL 60621"},
{label:"Arna Wendell Bontemps Elementary School", data:"1241 W 58th St  Chicago, IL 60636"},
{label:"Daniel Boone Elementary School", data:"6710 N Washtenaw Ave  Chicago, IL 60645"},
{label:"Edward A Bouchet Math & Science Academy ES", data:"7355 S Jeffery Blvd  Chicago, IL 60649"},
{label:"Myra Bradwell Communications Arts & Sciences ES", data:"7736 S Burnham Ave  Chicago, IL 60649"},
{label:"Joseph Brennemann Elementary School", data:"4251 N Clarendon Ave  Chicago, IL 60613"}, 
]; 
startAdd_cmb.dataProvider = new DataProvider(items);      
startAdd_cmb.addEventListener(ComponentEvent.ENTER, onAddItem);

function onAddItem(event:ComponentEvent):void { 
    var newRow:int = 0; 
    if (event.target.text == "Add") { 
        newRow = event.target.length + 1; 
            event.target.addItemAt({label:"screen" + newRow, data:"screenData" + newRow},  
            event.target.length);  
    } 
}
var dir:Directions;
var polyline:IPolyline;
var map:Map;
var startField:TextField;
var endField:TextField;
var so:SharedObject;

function setupMap()
{
	so = SharedObject.getLocal("locations");
	loadDestinations(startAdd_cmb.dataProvider, "from");
	loadDestinations(endAdd_cmb.dataProvider, "to");
	

	startAdd_cmb.addEventListener(Event.CHANGE, onSelectStartAddress);
	endAdd_cmb.addEventListener(Event.CHANGE, onSelectEndAddress);
	
	

	var holder:Sprite = new Sprite();
	startField = createNavTextField(10);
	holder.addChild(startField);
	
	endField = 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 = "Caculate";
	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, 26, 10);
	sprite.graphics.endFill();
	return sprite;
}

function loadDestinations(dp:DataProvider, name:String):void{
	if(so.data[name] != null){
		for(var i:Number = 0; i < so.data[name].length; i++){
			var item:String = so.data[name][i];
			addItem(dp, item, item);
		}
	}
}

function saveDestination(dp:DataProvider, name:String, field:TextField):void{
	if(so.data[name] == null)
		so.data[name] = [];
	if(so.data[name].indexOf(field.text) == -1){
		addItem(dp, field.text, field.text);
		so.data[name].push(field.text);
		so.flush();
	}
}

function addItem(dp:DataProvider, label:String, data:String):void{
	var item:SimpleCollectionItem = new SimpleCollectionItem();
	item.label = label;
	item.data = data;
	dp.addItem(item);
}

function onSelectStartAddress(e:Event):void {
	var item:SimpleCollectionItem = e.target.selectedItem as SimpleCollectionItem;
    startField.text = item.data;
}

function onSelectEndAddress(e:Event):void {
	var item:SimpleCollectionItem = e.target.selectedItem as SimpleCollectionItem;
    endField.text = item.data;
}

function onDirectionsLoaded(event:DirectionsEvent):void
{
	var ONE_METER:Number = 0.000621371192; // Miles 
	var returnedDirection:Directions = event.directions as Directions;
	var trainingTime: Number = Number(trainingTime_txt.text);
	var trainingCost: Number = Number(trainingCost_txt.text);
	var payRate: Number = Number(payRate_txt.text);
	var overallTrainingCost : Number = Math.round(trainingCost + (trainingTime * payRate));
	
	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";
	overallTrainingCost_txt.text = " The estimated total cost to attend this training is  " + "$" + overallTrainingCost;
	saveDestination(startAdd_cmb.dataProvider, "from", startField);
	saveDestination(endAdd_cmb.dataProvider, "to", endField);
	
	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.addControl(new ZoomControl());  
	map.addControl(new PositionControl());  
	map.addControl(new MapTypeControl());
	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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 

Author Comment

by:fool5683
ID: 36581246
Ok the following code is giving me the following error message:
" Scene 1, Layer 'Google Map', Frame 1, Line 71 1120: Access of undefined property on AddItem
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.controls.PositionControl;
import com.google.maps.controls.ZoomControl;
import com.google.maps.controls.MapTypeControl;
import com.google.maps.interfaces.IPolyline;
import com.google.maps.overlays.Marker;
import com.google.maps.overlays.MarkerOptions;
import com.google.maps.services.*;
import fl.data.SimpleCollectionItem;
import fl.data.DataProvider;
import fl.events.ComponentEvent;

var items:Array = [ 
{label:"Jane Addams Elementary School", data:"10810 S Avenue H  Chicago, IL 60617"},
{label:"Louis A Agassiz Elementary School", data:"2851 N Seminary Ave  Chicago, IL 60657"},
{label:"Air Force Academy High School", data:"3630 S Wells St  Chicago, IL 60609"},
{label:"Albany Park Multicultural Academy", data:"4929 N Sawyer Ave  Chicago, IL 60625"},
{label:"Louisa May Alcott Elementary School", data:"2625 N Orchard St  Chicago, IL 60614"},
{label:"Alcott High School for the Humanities", data:"2957 N Hoyne Ave  Chicago, IL 60618"},
{label:"Ira F Aldridge Elementary School", data:"630 E 131st St  Chicago, IL 60827"},
{label:"ALOP Alternative Schools", data:"4655 S Dearborn St  Chicago, IL 60609"},
{label:"John P Altgeld Elementary School", data:"1340 W 71st St  Chicago, IL 60636"},
{label:"Ames Middle School", data:"1340 W 71st St  Chicago, IL 60636"},
{label:"Roald Amundsen High School", data:"1920 N Hamlin Ave  Chicago, IL 60647"},
{label:"Ariel Elementary Community Academy", data:"5110 N Damen Ave  Chicago, IL 60625"},
{label:"Phillip D Armour Elementary School", data:"1119 E 46th St  Chicago, IL 60653"},
{label:"George Armstrong International Studies ES", data:"950 W 33rd Pl  Chicago, IL 60608"},
{label:"Louis Armstrong Math & Science Elementary School", data:"2110 W Greenleaf Ave  Chicago, IL 60645"},
{label:"Ashburn Community Elementary School", data:"8300 S Saint Louis Ave  Chicago, IL 60652"},
{label:"Arthur R Ashe Elementary School", data:"8505 S Ingleside Ave  Chicago, IL 60619"},
{label:"Crispus Attucks Elementary School", data:"5055 S State St  Chicago, IL 60609"},
{label:"John J Audubon Elementary School", data:"3500 N Hoyne Ave  Chicago, IL 60618"},
{label:"Austin Polytechnical Academy High School", data:"231 N Pine Ave  Chicago, IL 60644"},
{label:"Avalon Park Elementary School", data:"8045 S Kenwood Ave  Chicago, IL 60619"},
{label:"Mariano Azuela Elementary School", data:"4707 W Marquette Rd  Chicago, IL 60629"},
{label:"Benjamin Banneker Elementary School", data:"6656 S Normal Blvd  Chicago, IL 60621"},
{label:"Alice L Barnard Computer Math & Science Ctr ES", data:"10354 S Charles St  Chicago, IL 60643"},
{label:"John Barry Elementary School", data:"2828 N Kilbourn Ave  Chicago, IL 60641"},
{label:"Clara Barton Elementary School", data:"7650 S Wolcott Ave  Chicago, IL 60620"},
{label:"Perkins Bass Elementary School", data:"1140 W 66th St  Chicago, IL 60621"},
{label:"Newton Bateman Elementary School", data:"4220 N Richmond St  Chicago, IL 60618"},
{label:"Daniel C Beard Elementary School", data:"6445 W Strong St  Chicago, IL 60656"},
{label:"Edward Beasley Elementary Magnet Academic Center", data:"5255 S State St  Chicago, IL 60609"},
{label:"Jean Baptiste Beaubien Elementary School", data:"5025 N Laramie Ave  Chicago, IL 60630"},
{label:"Ludwig Van Beethoven Elementary School", data:"25 W 47th St  Chicago, IL 60609"},
{label:"Jacob Beidler Elementary School", data:"3151 W Walnut St  Chicago, IL 60612"},
{label:"Hiram H Belding Elementary School", data:"4257 N Tripp Ave  Chicago, IL 60641"},
{label:"Alexander Graham Bell Elementary School", data:"3730 N Oakley Ave  Chicago, IL 60618"},
{label:"Belmont-Cragin Elementary School", data:"2456 N Mango Ave  Chicago, IL 60639"},
{label:"Frank I Bennett Elementary School", data:"10115 S Prairie Ave  Chicago, IL 60628"},
{label:"Best Practice High School", data:"2040 W Adams St  Chicago, IL 60612"},
{label:"Mary McLeod Bethune Elementary School", data:"3030 W Arthington St  Chicago, IL 60612"},
{label:"Robert A Black Magnet Elementary School", data:"9101 S Euclid Ave  Chicago, IL 60619"},
{label:"James G Blaine Elementary School", data:"1420 W Grace St  Chicago, IL 60613"},
{label:"Blair Early Childhood Center", data:"6751 W 63rd Pl  Chicago, IL 60638"},
{label:"William J Bogan High School", data:"3939 W 79th St  Chicago, IL 60652"},
{label:"Carrie Jacobs Bond Elementary School", data:"7050 S May St  Chicago, IL 60621"},
{label:"Arna Wendell Bontemps Elementary School", data:"1241 W 58th St  Chicago, IL 60636"},
{label:"Daniel Boone Elementary School", data:"6710 N Washtenaw Ave  Chicago, IL 60645"},
{label:"Edward A Bouchet Math & Science Academy ES", data:"7355 S Jeffery Blvd  Chicago, IL 60649"},
{label:"Myra Bradwell Communications Arts & Sciences ES", data:"7736 S Burnham Ave  Chicago, IL 60649"},
{label:"Joseph Brennemann Elementary School", data:"4251 N Clarendon Ave  Chicago, IL 60613"}, 
]; 
startAdd_cmb.dataProvider = new DataProvider(items);      
startAdd_cmb.addEventListener(ComponentEvent.ENTER, onAddItem);

var dir:Directions;
var polyline:IPolyline;
var map:Map;
var startField:TextField;
var endField:TextField;
var so:SharedObject;

function setupMap()
{
	so = SharedObject.getLocal("locations");
	loadDestinations(startAdd_cmb.dataProvider, "from");
	loadDestinations(endAdd_cmb.dataProvider, "to");
	

	startAdd_cmb.addEventListener(Event.CHANGE, onSelectStartAddress);
	endAdd_cmb.addEventListener(Event.CHANGE, onSelectEndAddress);
	
	

	var holder:Sprite = new Sprite();
	startField = createNavTextField(10);
	holder.addChild(startField);
	
	endField = 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 = "Caculate";
	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, 26, 10);
	sprite.graphics.endFill();
	return sprite;
}

function loadDestinations(dp:DataProvider, name:String):void{
	if(so.data[name] != null){
		for(var i:Number = 0; i < so.data[name].length; i++){
			var item:String = so.data[name][i];
			addItem(dp, item, item);
		}
	}
}

function saveDestination(dp:DataProvider, name:String, field:TextField):void{
	if(so.data[name] == null)
		so.data[name] = [];
	if(so.data[name].indexOf(field.text) == -1){
		addItem(dp, field.text, field.text);
		so.data[name].push(field.text);
		so.flush();
	}
}

function addItem(dp:DataProvider, label:String, data:String):void{
	var item:SimpleCollectionItem = new SimpleCollectionItem();
	item.label = label;
	item.data = data;
	dp.addItem(item);
}

function onSelectStartAddress(e:Event):void {
	var item:SimpleCollectionItem = e.target.selectedItem as SimpleCollectionItem;
    startField.text = item.data;
}

function onSelectEndAddress(e:Event):void {
	var item:SimpleCollectionItem = e.target.selectedItem as SimpleCollectionItem;
    endField.text = item.data;
}

function onDirectionsLoaded(event:DirectionsEvent):void
{
	var ONE_METER:Number = 0.000621371192; // Miles 
	var returnedDirection:Directions = event.directions as Directions;
	var trainingTime: Number = Number(trainingTime_txt.text);
	var trainingCost: Number = Number(trainingCost_txt.text);
	var payRate: Number = Number(payRate_txt.text);
	var overallTrainingCost : Number = Math.round(trainingCost + (trainingTime * payRate));
	
	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";
	overallTrainingCost_txt.text = " The estimated total cost to attend this training is  " + "$" + overallTrainingCost;
	saveDestination(startAdd_cmb.dataProvider, "from", startField);
	saveDestination(endAdd_cmb.dataProvider, "to", endField);
	
	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.addControl(new ZoomControl());  
	map.addControl(new PositionControl());  
	map.addControl(new MapTypeControl());
	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
 
LVL 29

Expert Comment

by:dgofman
ID: 36583831
I can see you added listener but forget implement / add function "onAddItem" in your file

startAdd_cmb.addEventListener(ComponentEvent.ENTER, onAddItem);
0
 
LVL 29

Expert Comment

by:dgofman
ID: 36583860
And I am not sure you need this line because we are adding listeners in the setup function

      startAdd_cmb.addEventListener(Event.CHANGE, onSelectStartAddress);
      endAdd_cmb.addEventListener(Event.CHANGE, onSelectEndAddress);
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 

Author Comment

by:fool5683
ID: 36583929
So how would I correct these issues?
0
 
LVL 29

Expert Comment

by:dgofman
ID: 36583994
Comment

//startAdd_cmb.addEventListener(ComponentEvent.ENTER, onAddItem);
0
 

Author Comment

by:fool5683
ID: 36584389
I added that line and I am getting the following error message:

Access of undefined property onAddItem

What am I missing?
0
 
LVL 29

Expert Comment

by:dgofman
ID: 36584394
attach your FLA
0
 

Author Comment

by:fool5683
ID: 36584519
I tried uploadig file, but it would not allow it.
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.controls.PositionControl;
import com.google.maps.controls.ZoomControl;
import com.google.maps.controls.MapTypeControl;
import com.google.maps.interfaces.IPolyline;
import com.google.maps.overlays.Marker;
import com.google.maps.overlays.MarkerOptions;
import com.google.maps.services.*;
import fl.data.SimpleCollectionItem;
import fl.data.DataProvider;
import fl.events.ComponentEvent;

var items:Array = [ 
{label:"Jane Addams Elementary School", data:"10810 S Avenue H  Chicago, IL 60617"},
{label:"Louis A Agassiz Elementary School", data:"2851 N Seminary Ave  Chicago, IL 60657"},
{label:"Air Force Academy High School", data:"3630 S Wells St  Chicago, IL 60609"},
{label:"Albany Park Multicultural Academy", data:"4929 N Sawyer Ave  Chicago, IL 60625"},
{label:"Louisa May Alcott Elementary School", data:"2625 N Orchard St  Chicago, IL 60614"},
{label:"Alcott High School for the Humanities", data:"2957 N Hoyne Ave  Chicago, IL 60618"},
{label:"Ira F Aldridge Elementary School", data:"630 E 131st St  Chicago, IL 60827"},
{label:"ALOP Alternative Schools", data:"4655 S Dearborn St  Chicago, IL 60609"},
{label:"John P Altgeld Elementary School", data:"1340 W 71st St  Chicago, IL 60636"},
{label:"Ames Middle School", data:"1340 W 71st St  Chicago, IL 60636"},
{label:"Roald Amundsen High School", data:"1920 N Hamlin Ave  Chicago, IL 60647"},
{label:"Ariel Elementary Community Academy", data:"5110 N Damen Ave  Chicago, IL 60625"},
{label:"Phillip D Armour Elementary School", data:"1119 E 46th St  Chicago, IL 60653"},
{label:"George Armstrong International Studies ES", data:"950 W 33rd Pl  Chicago, IL 60608"},
{label:"Louis Armstrong Math & Science Elementary School", data:"2110 W Greenleaf Ave  Chicago, IL 60645"},
{label:"Ashburn Community Elementary School", data:"8300 S Saint Louis Ave  Chicago, IL 60652"},
{label:"Arthur R Ashe Elementary School", data:"8505 S Ingleside Ave  Chicago, IL 60619"},
{label:"Crispus Attucks Elementary School", data:"5055 S State St  Chicago, IL 60609"},
{label:"John J Audubon Elementary School", data:"3500 N Hoyne Ave  Chicago, IL 60618"},
{label:"Austin Polytechnical Academy High School", data:"231 N Pine Ave  Chicago, IL 60644"},
{label:"Avalon Park Elementary School", data:"8045 S Kenwood Ave  Chicago, IL 60619"},
{label:"Mariano Azuela Elementary School", data:"4707 W Marquette Rd  Chicago, IL 60629"},
{label:"Benjamin Banneker Elementary School", data:"6656 S Normal Blvd  Chicago, IL 60621"},
{label:"Alice L Barnard Computer Math & Science Ctr ES", data:"10354 S Charles St  Chicago, IL 60643"},
{label:"John Barry Elementary School", data:"2828 N Kilbourn Ave  Chicago, IL 60641"},
{label:"Clara Barton Elementary School", data:"7650 S Wolcott Ave  Chicago, IL 60620"},
{label:"Perkins Bass Elementary School", data:"1140 W 66th St  Chicago, IL 60621"},
{label:"Newton Bateman Elementary School", data:"4220 N Richmond St  Chicago, IL 60618"},
{label:"Daniel C Beard Elementary School", data:"6445 W Strong St  Chicago, IL 60656"},
{label:"Edward Beasley Elementary Magnet Academic Center", data:"5255 S State St  Chicago, IL 60609"},
{label:"Jean Baptiste Beaubien Elementary School", data:"5025 N Laramie Ave  Chicago, IL 60630"},
{label:"Ludwig Van Beethoven Elementary School", data:"25 W 47th St  Chicago, IL 60609"},
{label:"Jacob Beidler Elementary School", data:"3151 W Walnut St  Chicago, IL 60612"},
{label:"Hiram H Belding Elementary School", data:"4257 N Tripp Ave  Chicago, IL 60641"},
{label:"Alexander Graham Bell Elementary School", data:"3730 N Oakley Ave  Chicago, IL 60618"},
{label:"Belmont-Cragin Elementary School", data:"2456 N Mango Ave  Chicago, IL 60639"},
{label:"Frank I Bennett Elementary School", data:"10115 S Prairie Ave  Chicago, IL 60628"},
{label:"Best Practice High School", data:"2040 W Adams St  Chicago, IL 60612"},
{label:"Mary McLeod Bethune Elementary School", data:"3030 W Arthington St  Chicago, IL 60612"},
{label:"Robert A Black Magnet Elementary School", data:"9101 S Euclid Ave  Chicago, IL 60619"},
{label:"James G Blaine Elementary School", data:"1420 W Grace St  Chicago, IL 60613"},
{label:"Blair Early Childhood Center", data:"6751 W 63rd Pl  Chicago, IL 60638"},
{label:"William J Bogan High School", data:"3939 W 79th St  Chicago, IL 60652"},
{label:"Carrie Jacobs Bond Elementary School", data:"7050 S May St  Chicago, IL 60621"},
{label:"Arna Wendell Bontemps Elementary School", data:"1241 W 58th St  Chicago, IL 60636"},
{label:"Daniel Boone Elementary School", data:"6710 N Washtenaw Ave  Chicago, IL 60645"},
{label:"Edward A Bouchet Math & Science Academy ES", data:"7355 S Jeffery Blvd  Chicago, IL 60649"},
{label:"Myra Bradwell Communications Arts & Sciences ES", data:"7736 S Burnham Ave  Chicago, IL 60649"},
{label:"Joseph Brennemann Elementary School", data:"4251 N Clarendon Ave  Chicago, IL 60613"}, 
]; 
startAdd_cmb.dataProvider = new DataProvider(items);      
startAdd_cmb.addEventListener(ComponentEvent.ENTER, onAddItem);

var dir:Directions;
var polyline:IPolyline;
var map:Map;
var startField:TextField;
var endField:TextField;
var so:SharedObject;

function setupMap()
{
	so = SharedObject.getLocal("locations");
	loadDestinations(startAdd_cmb.dataProvider, "from");
	loadDestinations(endAdd_cmb.dataProvider, "to");
	

	endAdd_cmb.addEventListener(Event.CHANGE, onSelectEndAddress);
	startAdd_cmb.addEventListener(ComponentEvent.ENTER, onAddItem); 
	

	var holder:Sprite = new Sprite();
	startField = createNavTextField(10);
	holder.addChild(startField);
	
	endField = 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 = "Caculate";
	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, 26, 10);
	sprite.graphics.endFill();
	return sprite;
}

function loadDestinations(dp:DataProvider, name:String):void{
	if(so.data[name] != null){
		for(var i:Number = 0; i < so.data[name].length; i++){
			var item:String = so.data[name][i];
			addItem(dp, item, item);
		}
	}
}

function saveDestination(dp:DataProvider, name:String, field:TextField):void{
	if(so.data[name] == null)
		so.data[name] = [];
	if(so.data[name].indexOf(field.text) == -1){
		addItem(dp, field.text, field.text);
		so.data[name].push(field.text);
		so.flush();
	}
}

function addItem(dp:DataProvider, label:String, data:String):void{
	var item:SimpleCollectionItem = new SimpleCollectionItem();
	item.label = label;
	item.data = data;
	dp.addItem(item);
}

function onSelectStartAddress(e:Event):void {
	var item:SimpleCollectionItem = e.target.selectedItem as SimpleCollectionItem;
    startField.text = item.data;
}

function onSelectEndAddress(e:Event):void {
	var item:SimpleCollectionItem = e.target.selectedItem as SimpleCollectionItem;
    endField.text = item.data;
}

function onDirectionsLoaded(event:DirectionsEvent):void
{
	var ONE_METER:Number = 0.000621371192; // Miles 
	var returnedDirection:Directions = event.directions as Directions;
	var trainingTime: Number = Number(trainingTime_txt.text);
	var trainingCost: Number = Number(trainingCost_txt.text);
	var payRate: Number = Number(payRate_txt.text);
	var overallTrainingCost : Number = Math.round(trainingCost + (trainingTime * payRate));
	
	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";
	overallTrainingCost_txt.text = " The estimated total cost to attend this training is  " + "$" + overallTrainingCost;
	saveDestination(startAdd_cmb.dataProvider, "from", startField);
	saveDestination(endAdd_cmb.dataProvider, "to", endField);
	
	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.addControl(new ZoomControl());  
	map.addControl(new PositionControl());  
	map.addControl(new MapTypeControl());
	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
 
LVL 29

Expert Comment

by:dgofman
ID: 36584528
Save as CS4 version and you will able to upload
0
 
LVL 29

Accepted Solution

by:
dgofman earned 2000 total points
ID: 36584536
Man,  I asked to do very simple change (comment first listener) and you did completely opposite.
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.controls.PositionControl;
import com.google.maps.controls.ZoomControl;
import com.google.maps.controls.MapTypeControl;
import com.google.maps.interfaces.IPolyline;
import com.google.maps.overlays.Marker;
import com.google.maps.overlays.MarkerOptions;
import com.google.maps.services.*;
import fl.data.SimpleCollectionItem;
import fl.data.DataProvider;
import fl.events.ComponentEvent;

var items:Array = [ 
{label:"Jane Addams Elementary School", data:"10810 S Avenue H  Chicago, IL 60617"},
{label:"Louis A Agassiz Elementary School", data:"2851 N Seminary Ave  Chicago, IL 60657"},
{label:"Air Force Academy High School", data:"3630 S Wells St  Chicago, IL 60609"},
{label:"Albany Park Multicultural Academy", data:"4929 N Sawyer Ave  Chicago, IL 60625"},
{label:"Louisa May Alcott Elementary School", data:"2625 N Orchard St  Chicago, IL 60614"},
{label:"Alcott High School for the Humanities", data:"2957 N Hoyne Ave  Chicago, IL 60618"},
{label:"Ira F Aldridge Elementary School", data:"630 E 131st St  Chicago, IL 60827"},
{label:"ALOP Alternative Schools", data:"4655 S Dearborn St  Chicago, IL 60609"},
{label:"John P Altgeld Elementary School", data:"1340 W 71st St  Chicago, IL 60636"},
{label:"Ames Middle School", data:"1340 W 71st St  Chicago, IL 60636"},
{label:"Roald Amundsen High School", data:"1920 N Hamlin Ave  Chicago, IL 60647"},
{label:"Ariel Elementary Community Academy", data:"5110 N Damen Ave  Chicago, IL 60625"},
{label:"Phillip D Armour Elementary School", data:"1119 E 46th St  Chicago, IL 60653"},
{label:"George Armstrong International Studies ES", data:"950 W 33rd Pl  Chicago, IL 60608"},
{label:"Louis Armstrong Math & Science Elementary School", data:"2110 W Greenleaf Ave  Chicago, IL 60645"},
{label:"Ashburn Community Elementary School", data:"8300 S Saint Louis Ave  Chicago, IL 60652"},
{label:"Arthur R Ashe Elementary School", data:"8505 S Ingleside Ave  Chicago, IL 60619"},
{label:"Crispus Attucks Elementary School", data:"5055 S State St  Chicago, IL 60609"},
{label:"John J Audubon Elementary School", data:"3500 N Hoyne Ave  Chicago, IL 60618"},
{label:"Austin Polytechnical Academy High School", data:"231 N Pine Ave  Chicago, IL 60644"},
{label:"Avalon Park Elementary School", data:"8045 S Kenwood Ave  Chicago, IL 60619"},
{label:"Mariano Azuela Elementary School", data:"4707 W Marquette Rd  Chicago, IL 60629"},
{label:"Benjamin Banneker Elementary School", data:"6656 S Normal Blvd  Chicago, IL 60621"},
{label:"Alice L Barnard Computer Math & Science Ctr ES", data:"10354 S Charles St  Chicago, IL 60643"},
{label:"John Barry Elementary School", data:"2828 N Kilbourn Ave  Chicago, IL 60641"},
{label:"Clara Barton Elementary School", data:"7650 S Wolcott Ave  Chicago, IL 60620"},
{label:"Perkins Bass Elementary School", data:"1140 W 66th St  Chicago, IL 60621"},
{label:"Newton Bateman Elementary School", data:"4220 N Richmond St  Chicago, IL 60618"},
{label:"Daniel C Beard Elementary School", data:"6445 W Strong St  Chicago, IL 60656"},
{label:"Edward Beasley Elementary Magnet Academic Center", data:"5255 S State St  Chicago, IL 60609"},
{label:"Jean Baptiste Beaubien Elementary School", data:"5025 N Laramie Ave  Chicago, IL 60630"},
{label:"Ludwig Van Beethoven Elementary School", data:"25 W 47th St  Chicago, IL 60609"},
{label:"Jacob Beidler Elementary School", data:"3151 W Walnut St  Chicago, IL 60612"},
{label:"Hiram H Belding Elementary School", data:"4257 N Tripp Ave  Chicago, IL 60641"},
{label:"Alexander Graham Bell Elementary School", data:"3730 N Oakley Ave  Chicago, IL 60618"},
{label:"Belmont-Cragin Elementary School", data:"2456 N Mango Ave  Chicago, IL 60639"},
{label:"Frank I Bennett Elementary School", data:"10115 S Prairie Ave  Chicago, IL 60628"},
{label:"Best Practice High School", data:"2040 W Adams St  Chicago, IL 60612"},
{label:"Mary McLeod Bethune Elementary School", data:"3030 W Arthington St  Chicago, IL 60612"},
{label:"Robert A Black Magnet Elementary School", data:"9101 S Euclid Ave  Chicago, IL 60619"},
{label:"James G Blaine Elementary School", data:"1420 W Grace St  Chicago, IL 60613"},
{label:"Blair Early Childhood Center", data:"6751 W 63rd Pl  Chicago, IL 60638"},
{label:"William J Bogan High School", data:"3939 W 79th St  Chicago, IL 60652"},
{label:"Carrie Jacobs Bond Elementary School", data:"7050 S May St  Chicago, IL 60621"},
{label:"Arna Wendell Bontemps Elementary School", data:"1241 W 58th St  Chicago, IL 60636"},
{label:"Daniel Boone Elementary School", data:"6710 N Washtenaw Ave  Chicago, IL 60645"},
{label:"Edward A Bouchet Math & Science Academy ES", data:"7355 S Jeffery Blvd  Chicago, IL 60649"},
{label:"Myra Bradwell Communications Arts & Sciences ES", data:"7736 S Burnham Ave  Chicago, IL 60649"},
{label:"Joseph Brennemann Elementary School", data:"4251 N Clarendon Ave  Chicago, IL 60613"}, 
]; 
startAdd_cmb.dataProvider = new DataProvider(items);      
//startAdd_cmb.addEventListener(ComponentEvent.ENTER, onAddItem);

var dir:Directions;
var polyline:IPolyline;
var map:Map;
var startField:TextField;
var endField:TextField;
var so:SharedObject;

function setupMap()
{
	so = SharedObject.getLocal("locations");
	loadDestinations(startAdd_cmb.dataProvider, "from");
	loadDestinations(endAdd_cmb.dataProvider, "to");
	

	endAdd_cmb.addEventListener(Event.CHANGE, onSelectEndAddress);
	startAdd_cmb.addEventListener(ComponentEvent.ENTER, onSelectStartAddress); 
	

	var holder:Sprite = new Sprite();
	startField = createNavTextField(10);
	holder.addChild(startField);
	
	endField = 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 = "Caculate";
	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, 26, 10);
	sprite.graphics.endFill();
	return sprite;
}

function loadDestinations(dp:DataProvider, name:String):void{
	if(so.data[name] != null){
		for(var i:Number = 0; i < so.data[name].length; i++){
			var item:String = so.data[name][i];
			addItem(dp, item, item);
		}
	}
}

function saveDestination(dp:DataProvider, name:String, field:TextField):void{
	if(so.data[name] == null)
		so.data[name] = [];
	if(so.data[name].indexOf(field.text) == -1){
		addItem(dp, field.text, field.text);
		so.data[name].push(field.text);
		so.flush();
	}
}

function addItem(dp:DataProvider, label:String, data:String):void{
	var item:SimpleCollectionItem = new SimpleCollectionItem();
	item.label = label;
	item.data = data;
	dp.addItem(item);
}

function onSelectStartAddress(e:Event):void {
	var item:SimpleCollectionItem = e.target.selectedItem as SimpleCollectionItem;
    startField.text = item.data;
}

function onSelectEndAddress(e:Event):void {
	var item:SimpleCollectionItem = e.target.selectedItem as SimpleCollectionItem;
    endField.text = item.data;
}

function onDirectionsLoaded(event:DirectionsEvent):void
{
	var ONE_METER:Number = 0.000621371192; // Miles 
	var returnedDirection:Directions = event.directions as Directions;
	var trainingTime: Number = Number(trainingTime_txt.text);
	var trainingCost: Number = Number(trainingCost_txt.text);
	var payRate: Number = Number(payRate_txt.text);
	var overallTrainingCost : Number = Math.round(trainingCost + (trainingTime * payRate));
	
	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";
	overallTrainingCost_txt.text = " The estimated total cost to attend this training is  " + "$" + overallTrainingCost;
	saveDestination(startAdd_cmb.dataProvider, "from", startField);
	saveDestination(endAdd_cmb.dataProvider, "to", endField);
	
	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.addControl(new ZoomControl());  
	map.addControl(new PositionControl());  
	map.addControl(new MapTypeControl());
	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
 
LVL 29

Expert Comment

by:dgofman
ID: 36584561
Plus you cannot assign object into your combobox you have to append items

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.controls.PositionControl;
import com.google.maps.controls.ZoomControl;
import com.google.maps.controls.MapTypeControl;
import com.google.maps.interfaces.IPolyline;
import com.google.maps.overlays.Marker;
import com.google.maps.overlays.MarkerOptions;
import com.google.maps.services.*;
import fl.data.SimpleCollectionItem;
import fl.data.DataProvider;
import fl.events.ComponentEvent;

var items:Array = [ 
{label:"Jane Addams Elementary School", data:"10810 S Avenue H  Chicago, IL 60617"},
{label:"Louis A Agassiz Elementary School", data:"2851 N Seminary Ave  Chicago, IL 60657"},
{label:"Air Force Academy High School", data:"3630 S Wells St  Chicago, IL 60609"},
{label:"Albany Park Multicultural Academy", data:"4929 N Sawyer Ave  Chicago, IL 60625"},
{label:"Louisa May Alcott Elementary School", data:"2625 N Orchard St  Chicago, IL 60614"},
{label:"Alcott High School for the Humanities", data:"2957 N Hoyne Ave  Chicago, IL 60618"},
{label:"Ira F Aldridge Elementary School", data:"630 E 131st St  Chicago, IL 60827"},
{label:"ALOP Alternative Schools", data:"4655 S Dearborn St  Chicago, IL 60609"},
{label:"John P Altgeld Elementary School", data:"1340 W 71st St  Chicago, IL 60636"},
{label:"Ames Middle School", data:"1340 W 71st St  Chicago, IL 60636"},
{label:"Roald Amundsen High School", data:"1920 N Hamlin Ave  Chicago, IL 60647"},
{label:"Ariel Elementary Community Academy", data:"5110 N Damen Ave  Chicago, IL 60625"},
{label:"Phillip D Armour Elementary School", data:"1119 E 46th St  Chicago, IL 60653"},
{label:"George Armstrong International Studies ES", data:"950 W 33rd Pl  Chicago, IL 60608"},
{label:"Louis Armstrong Math & Science Elementary School", data:"2110 W Greenleaf Ave  Chicago, IL 60645"},
{label:"Ashburn Community Elementary School", data:"8300 S Saint Louis Ave  Chicago, IL 60652"},
{label:"Arthur R Ashe Elementary School", data:"8505 S Ingleside Ave  Chicago, IL 60619"},
{label:"Crispus Attucks Elementary School", data:"5055 S State St  Chicago, IL 60609"},
{label:"John J Audubon Elementary School", data:"3500 N Hoyne Ave  Chicago, IL 60618"},
{label:"Austin Polytechnical Academy High School", data:"231 N Pine Ave  Chicago, IL 60644"},
{label:"Avalon Park Elementary School", data:"8045 S Kenwood Ave  Chicago, IL 60619"},
{label:"Mariano Azuela Elementary School", data:"4707 W Marquette Rd  Chicago, IL 60629"},
{label:"Benjamin Banneker Elementary School", data:"6656 S Normal Blvd  Chicago, IL 60621"},
{label:"Alice L Barnard Computer Math & Science Ctr ES", data:"10354 S Charles St  Chicago, IL 60643"},
{label:"John Barry Elementary School", data:"2828 N Kilbourn Ave  Chicago, IL 60641"},
{label:"Clara Barton Elementary School", data:"7650 S Wolcott Ave  Chicago, IL 60620"},
{label:"Perkins Bass Elementary School", data:"1140 W 66th St  Chicago, IL 60621"},
{label:"Newton Bateman Elementary School", data:"4220 N Richmond St  Chicago, IL 60618"},
{label:"Daniel C Beard Elementary School", data:"6445 W Strong St  Chicago, IL 60656"},
{label:"Edward Beasley Elementary Magnet Academic Center", data:"5255 S State St  Chicago, IL 60609"},
{label:"Jean Baptiste Beaubien Elementary School", data:"5025 N Laramie Ave  Chicago, IL 60630"},
{label:"Ludwig Van Beethoven Elementary School", data:"25 W 47th St  Chicago, IL 60609"},
{label:"Jacob Beidler Elementary School", data:"3151 W Walnut St  Chicago, IL 60612"},
{label:"Hiram H Belding Elementary School", data:"4257 N Tripp Ave  Chicago, IL 60641"},
{label:"Alexander Graham Bell Elementary School", data:"3730 N Oakley Ave  Chicago, IL 60618"},
{label:"Belmont-Cragin Elementary School", data:"2456 N Mango Ave  Chicago, IL 60639"},
{label:"Frank I Bennett Elementary School", data:"10115 S Prairie Ave  Chicago, IL 60628"},
{label:"Best Practice High School", data:"2040 W Adams St  Chicago, IL 60612"},
{label:"Mary McLeod Bethune Elementary School", data:"3030 W Arthington St  Chicago, IL 60612"},
{label:"Robert A Black Magnet Elementary School", data:"9101 S Euclid Ave  Chicago, IL 60619"},
{label:"James G Blaine Elementary School", data:"1420 W Grace St  Chicago, IL 60613"},
{label:"Blair Early Childhood Center", data:"6751 W 63rd Pl  Chicago, IL 60638"},
{label:"William J Bogan High School", data:"3939 W 79th St  Chicago, IL 60652"},
{label:"Carrie Jacobs Bond Elementary School", data:"7050 S May St  Chicago, IL 60621"},
{label:"Arna Wendell Bontemps Elementary School", data:"1241 W 58th St  Chicago, IL 60636"},
{label:"Daniel Boone Elementary School", data:"6710 N Washtenaw Ave  Chicago, IL 60645"},
{label:"Edward A Bouchet Math & Science Academy ES", data:"7355 S Jeffery Blvd  Chicago, IL 60649"},
{label:"Myra Bradwell Communications Arts & Sciences ES", data:"7736 S Burnham Ave  Chicago, IL 60649"},
{label:"Joseph Brennemann Elementary School", data:"4251 N Clarendon Ave  Chicago, IL 60613"}, 
]; 


var dir:Directions;
var polyline:IPolyline;
var map:Map;
var startField:TextField;
var endField:TextField;
var so:SharedObject;

function setupMap()
{
	so = SharedObject.getLocal("locations");
	loadDestinations(startAdd_cmb.dataProvider, "from");
	loadDestinations(endAdd_cmb.dataProvider, "to");
	
	for(var i:uint = 0; i < items.length; i++){
		var item:Object = items[i];
		addItem(startAdd_cmb.dataProvider, item.label, item.data);
		addItem(endAdd_cmb.dataProvider, item.label, item.data);
	}

	endAdd_cmb.addEventListener(Event.CHANGE, onSelectEndAddress);
	startAdd_cmb.addEventListener(Event.CHANGE, onSelectStartAddress); 

	var holder:Sprite = new Sprite();
	startField = createNavTextField(10);
	holder.addChild(startField);
	
	endField = 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 = "Caculate";
	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, 26, 10);
	sprite.graphics.endFill();
	return sprite;
}

function loadDestinations(dp:DataProvider, name:String):void{
	if(so.data[name] != null){
		for(var i:Number = 0; i < so.data[name].length; i++){
			var item:String = so.data[name][i];
			addItem(dp, item, item);
		}
	}
}

function saveDestination(dp:DataProvider, name:String, field:TextField):void{
	if(so.data[name] == null)
		so.data[name] = [];
	if(so.data[name].indexOf(field.text) == -1){
		addItem(dp, field.text, field.text);
		so.data[name].push(field.text);
		so.flush();
	}
}

function addItem(dp:DataProvider, label:String, data:String):void{
	var item:SimpleCollectionItem = new SimpleCollectionItem();
	item.label = label;
	item.data = data;
	dp.addItem(item);
}

function onSelectStartAddress(e:Event):void {
	var item:SimpleCollectionItem = e.target.selectedItem as SimpleCollectionItem;
    startField.text = item.data;
}

function onSelectEndAddress(e:Event):void {
	var item:SimpleCollectionItem = e.target.selectedItem as SimpleCollectionItem;
    endField.text = item.data;
}

function onDirectionsLoaded(event:DirectionsEvent):void
{
	var ONE_METER:Number = 0.000621371192; // Miles 
	var returnedDirection:Directions = event.directions as Directions;
	var trainingTime: Number = Number(trainingTime_txt.text);
	var trainingCost: Number = Number(trainingCost_txt.text);
	var payRate: Number = Number(payRate_txt.text);
	var overallTrainingCost : Number = Math.round(trainingCost + (trainingTime * payRate));
	
	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";
	overallTrainingCost_txt.text = " The estimated total cost to attend this training is  " + "$" + overallTrainingCost;
	saveDestination(startAdd_cmb.dataProvider, "from", startField);
	saveDestination(endAdd_cmb.dataProvider, "to", endField);
	
	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.addControl(new ZoomControl());  
	map.addControl(new PositionControl());  
	map.addControl(new MapTypeControl());
	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
 

Author Closing Comment

by:fool5683
ID: 36584692
Awesome!!!!
I really really appreciate your help. I am slowly but surely learning this Flash/actionscript stuff:)

Danke!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

715 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