jump to navigation

Manipulating the ComboBox in Flash CS3 September 12, 2010

Posted by Tournas Dimitrios in Flash.
trackback

These code snippets are just a note for me . They will be a reference for future projects .I hope they will also be helpful for other Flash developers.

  • Styling and accessing data from a ComboBox
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.font = "Comic Sans MS";
myTextFormat.color = 0xFF0000;
myTextFormat.size = 14;

// create and apply style to comboBox

var myComboBox:ComboBox = new ComboBox();
myComboBox.x=myComboBox.y= 100;
myComboBox.setSize(200 , 22);
myComboBox.prompt = "Selem alecum";
myComboBox.addItem( { label:"item1" , data:"http://firstitem.com" } );
myComboBox.addItem( { label:"item2" , data:"http://secondItem.com"} );
myComboBox.textField.setStyle("textFormat", myTextFormat);
addChild(myComboBox);
myComboBox.addEventListener(Event.CHANGE , changeEvt);

function changeEvt(e:Event):void {
 trace(e.target.selectedItem.data);
 }

  • How to link to a webpage
import fl.controls.ComboBox;
import fl.data.DataProvider;


var arr:Array = [{label:"In.gr" , data:"http://www.in.gr"} ,
				 { label:"Amazon.com" , data:"http://www.amazon.com"} ,
				 {  label:"Yahoo.com" , data:"http://www.yahoo.com"}];

var inf:DataProvider = new DataProvider(arr);
var myco:ComboBox = new ComboBox();
addChild(myco);
myco.dataProvider = inf;
myco.prompt = "Select a website";
myco.width = 120;
myco.selectedIndex = -1;
myco.addEventListener(Event.CHANGE , gotoUrl);


function gotoUrl(e:Event):void {
	var num:Number = e.target.selectedIndex;
	trace(num);
		
	var request:URLRequest = new URLRequest();
    request.url = ComboBox(e.target).selectedItem.data;
    navigateToURL(request);
   
}

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s