[ActionScript] ComboBoxの実装例

9:02 PM on 2011年5月20日 ,

import fl.controls.ComboBox;
import fl.data.DataProvider;
import flash.net.navigateToURL;
import flash.net.URLRequest;

var ary:Array = new Array({label:"home", data:"http://www.project0884.com/"},
                          {label:"blog", data:"http://project0884.com/wp/"}); 

var cmb : ComboBox = new ComboBox();
//cmb.dropdownWidth = 100;
//cmb.width = 100;
cmb.move(10, 10);
cmb.prompt = "select";
cmb.dataProvider = new DataProvider(ary);
cmb.addEventListener(Event.CHANGE, changeHandler);
addChild(cmb);

function changeHandler(event:Event):void {
    var request:URLRequest = new URLRequest();
    request.url = ComboBox(event.target).selectedItem.data;
    navigateToURL(request);
}