Flex: CheckBox Tree

效果与功能:

1. 简单配置数据源即可实现多层显示 2. 可设定初始选定的项目或目录 3. 获得选定的项目

Flex: 汉字转拼音

Flex中将汉字转换为拼音:

使用方法:

var han2pinyin:HanZi2PinYin = new HanZi2PinYin();
Alert.show(han2pinyin.toPinyin("汉字"));

HanZi2PinYin类下载:

Box: http://www.box.net/shared/t8ucn0bz4i

代码非本人原创, 出处:http://www.ppzhao.net/index.php/archives/175

Flex: DataGrid使用ListEvent.ITEM_DOUBLE_CLICK监听双击事件

之前没怎么注意, 一直用MouseEvent.DOUBLE_CLICK来监听DataGrid的双击事件. 但这样会造成即使在空行双击也会激发响应.

datagridClasses.doubleClickEnabled = true;
datagridClasses.addEventListener(MouseEvent.DOUBLE_CLICK, onDGDoubleClicked);

正确方法应该使用ListEvent.ITEM_DOUBLE_CLICK监听项目双击事件.

datagridClasses.addEventListener(ListEvent.ITEM_DOUBLE_CLICK, onDGDoubleClicked);

Flex: 使用URLRequest下载文件时的权限验证

权限验证:

var fileRef:FileReference = new FileReference();
var request:URLRequest = new URLRequest(serviceUrl);

request.method = URLRequestMethod.POST;
var encoder : Base64Encoder = new Base64Encoder();
encoder.encode(userName + ":" + password);
request.requestHeaders.push(new URLRequestHeader("Authorization", "Basic " + encoder.toString())); // ** 增加认证信息

fileRef.addEventListener(Event.OPEN, onFileDownloadBegin);
fileRef.addEventListener(Event.COMPLETE, onFileDownloadComplete);
fileRef.addEventListener(IOErrorEvent.IO_ERROR, onFileDownloadError);
fileRef.addEventListener(Event.CANCEL, onFileDownLoadCancel);
fileRef.download(request, getExportFileName(serviceUrl));

Flex: 使用URLRequest进行下载, 并监听有关事件

使用URLRequest下载文件. – 无权限认证

// 下载文件
protected function downloadTemplateFile():void {
var fileRef:FileReference = new FileReference();
var urlReq:URLRequest = new URLRequest(_pathTemplateFile);
fileRef.addEventListener(Event.OPEN,onDownloadBegin);
fileRef.addEventListener(Event.COMPLETE, onDownloadComplete);
fileRef.addEventListener(Event.CANCEL, onDownloadCancel);
fileRef.addEventListener(IOErrorEvent.IO_ERROR, onDownloadError);
fileRef.download(urlReq);
}

// 模板文件下载开始时响应.
protected function onDownloadBegin(e:Event):void {
appendTextToOutPut(RM.getString(BUNDLE_ASMT_MGT, "template.download.begin"));
}

// 当下载结束后响应. */
protected function onDownloadComplete(e:Event):void {
var file:FileReference = e.target as FileReference;
appendTextToOutPut(RM.getString(BUNDLE_ASMT_MGT, "template.download.success", [file.name, FileUtils.formatFileSize(file.size)]));
log.info("模板文件下载结束: " + file.name + "-" + file.size);
}

// 当下载取消时响应. */
protected function onDownloadCancel(e:Event):void {
appendTextToOutPut(RM.getString(BUNDLE_ASMT_MGT, "controller.download.canceled"));
}

// 当下载出现错误时响应. */
protected function onDownloadError(e:IOError):void {
appendTextToOutPut(RM.getString(BUNDLE_ASMT_MGT, "template.download.error", [...]