DragDrop时, 使用DragEvent.dragInitiator来获得Drag源头, 而非DragEvent.relatedObject

Categories: Flex; Tagged with: ; @ January 21st, 2010 17:23

首发: http://riashanghai.com/node/123

问题描述:

在进行DragDrop时, 我使用了DragDrop.relatedObject来获得Drag触发的UIComponent

如: var dargUI:TileList = e.relatedObject as TileList;

在AIR中运行, 可用且没有任何错误, 但当使用浏览器版本时, e.relatedObject为null, 上一行代码报错.

 

解决方法:

因此, 如果需要在两种环境中都可以运行, 应使用e.dragInitiator来获取Drag触发的源头:

	//----------------------------------
	//  dragInitiator 来源: DragEvent
	//----------------------------------

	/**
	 *  The component that initiated the drag.
	 */
	public var dragInitiator:IUIComponent;

Flex: Datagrid派发ITEM_EDIT_BEGIN后因fm/focusManager为Null报错的解决方法

Categories: Flex; Tagged with: ; @ January 15th, 2010 22:09

某DataGrid 监听Editor_BEGIN事件, 如果有数据未保存切换界面时, 会弹出Alert, 在弹出Alert之后, 确定切换界面时, DataGrid报错:
DataGrid的itemEditorItemEditBeginHandler方法中:
var fm:IFocusManager = focusManager; 该fm也就是focusManager为Null, 导致出现错误.
恰好focusManager属性为Protected.
解决方法, 在DataGridGrade(该类继承了DataGrid)的onEditBegin方法中增加了

if(focusManager == null) {
	e.preventDefault()
	return;
}

Flex: HttpService正常返回Html, 但派发FaultEvent事件的解决方法

Categories: Flex; Tagged with: ; @ January 15th, 2010 21:51

HttpService的默认resultFormat为”object” HTTPService.RESULT_FORMAT_OBJECT 在服务器响应后, AbstractOperatoin.processResult()会对响应进行初步处理,

if (resultFormat == RESULT_FORMAT_XML || resultFormat == RESULT_FORMAT_OBJECT 
                    || resultFormat == RESULT_FORMAT_ARRAY)
            {
                //old XML style
                var tmp:Object = new XMLDocument();
                XMLDocument(tmp).ignoreWhite = true;
                try
                {
                    XMLDocument(tmp).parseXML(String(body));
                }
                catch(parseError:Error)
                {
                    var fault:Fault = new Fault(ERROR_DECODING, parseError.message);
                    dispatchRpcEvent(FaultEvent.createEvent(fault, token, message));
                    return false;
                }
		....
}



因此, 如果HttpService不set resultFormat的话, 会默认作为xml进行解析, 此时如出现错误, 则会派发FaultEvent.
为避免此问题, 可设定:
httpService.resultFormat = HTTPService.RESULT_FORMAT_TEXT;

Flex:使用正则表达式替换String

Categories: Flex; Tagged with: ; @ January 15th, 2010 21:40

需求: 通过某些字符串生成文件名称, 简单要求: 仅允许数字或字母及”_”
代码:

var regExp:RegExp = new RegExp("[^A-Za-z0-9_]", "g"); // 正则表达式, 将非字母数字或下划线的字符替换为"_", 全部替换.
		finalName = fileName.replace(regExp, "_");
		

Flex: 将Date输出为YYYYMMDDHHMMSS格式

Categories: Flex; Tagged with: ; @ January 15th, 2010 21:34
	/** 将给定的Date输出为YYYYMMDDHHMMSS格式, 如:20100115091809., */
	public static function dateToString(date:Date):String {
		if(date == null) {
			return null;
		}else{
			return date.fullYear.toString() + (date.month + 1 < 10 ? "0" : "") + (date.month + 1) +
				(date.date < 10 ? "0" : "") + date.date + (date.hours < 10 ? "0" : "") + date.hours +
				(date.minutes < 10 ? "0" : "") + date.minutes + (date.seconds < 10 ? "0" : "") + date.seconds;
		}
	}

Newer Posts <-> Older Posts



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.