Hyperlinks for Flash Combo Box Items

MistahT
MistahT used Ask the Experts™
on
Hi Everybody,

I'd like to add hyperlinks to the items in my combo box in Flash CS4.
The combo box will act as a navigation to different websites.

Can anyone please explain to me how to do it?


This is the code so far:

function subList():void {
      cb1.addItem( { label: "INTRODUCTION" } );
      cb1.addItem( { label: "HISTORY" } );
      cb1.addItem( { label: "OBJECTIVES" } );
      cb1.addItem( { label: "PERFORMANCE" } );
      cb1.addItem( { label: "MANAGEMENT" } );
}


function subClick (event:MouseEvent):void {
      cb1.removeAll();
      subList();
}



cb1.addEventListener(MouseEvent.CLICK, subClick);




Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2009
Commented:
first of all add a change listener to combo box so you know when something has been selected.

then get the selected item label.
then store that and pass it through to navigateToURL.

example:


cb1.addEventListener(Event.CHANGE, enterHandler);

function enterHandler(e:Event):void
{
	trace(e.currentTarget.selectedItem.label);
	gotoSite(e.currentTarget.selectedItem.label);

}

function gotoSite(str:String):void
{
	switch (str) {
		case "OBJECTIVES":
			urlRequest = new URLRequest("http://www.google.co.za");
			navigateToURL(urlRequest);
			break;
		case "PERFORMANCE":
			urlRequest = new URLRequest("http://www.news24.com");
			navigateToURL(urlRequest);
			break;
	}
}

Open in new window

Author

Commented:
Hi blue-genie,

thanks so much for the quick reply! :)


I pasted your code, but receive the error:

1120: Access of undefined property urlRequest.
function subList():void {
	cb1.addItem( { label: "INTRODUCTION" } );
	cb1.addItem( { label: "HISTORY" } );
	cb1.addItem( { label: "OBJECTIVES" } );
	cb1.addItem( { label: "PERFORMANCE" } );
	cb1.addItem( { label: "MANAGEMENT" } );
	
}


function subClick (event:MouseEvent):void {
	cb1.removeAll();
	subList();
}



cb1.addEventListener(MouseEvent.CLICK, subClick);






cb1.addEventListener(Event.CHANGE, enterHandler);

function enterHandler(e:Event):void
{
	trace(e.currentTarget.selectedItem.label);
	gotoSite(e.currentTarget.selectedItem.label);

}




function gotoSite(str:String):void
{
	switch (str) {
		case "OBJECTIVES":
			urlRequest = new URLRequest("objectives.htm");
			navigateToURL(urlRequest);
			break;
		case "PERFORMANCE":
			urlRequest = new URLRequest("performance.htm");
			navigateToURL(urlRequest);
			break;
	}
}

Open in new window

Top Expert 2009

Commented:
i take it you figured out you need to import the URLRequest class?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial