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;
		}
	}

Flex SharedObject 使用举例

Categories: Flex; Tagged with: ; @ January 14th, 2010 21:07

需求: 需要将某个UI上的几条输入项目存到SharedObject中, 每次Application关闭时进行存储, 开启Application时, 读取上次保存的值并set到ui上.

效果:

image

每次关闭前, 将会保存最后一次更改的数据; 每次开启前, 将读取上次保存的数据并set到ui上.

代码:

Application Event Listener: creationComplete=”onCreateComplete()” closing=”onClosing(event)”

		/** 当Application初始化完毕后响应. */
		protected function onCreateComplete(e:Event = null):void {
			// 在Application启动时, 从SharedObject中读取数据, 刷新UI.
			var adminConsoleSharedObject:SharedObject = SharedObject.getLocal("adminConsoleSharedObject", "/");
			consoleUI.setInitVaules([adminConsoleSharedObject.data.baseUrl, adminConsoleSharedObject.data.userName, adminConsoleSharedObject.data.password]);
		}

		/** 当Application关闭时响应, 在每次关闭前, 将有关数据保存到SharedObject中. */
		protected function onClosing(event:Event):void {
			var adminConsoleSharedObject:SharedObject = SharedObject.getLocal("adminConsoleSharedObject", "/");
			adminConsoleSharedObject.data.baseUrl = consoleUI.getBaseUrl();
			adminConsoleSharedObject.data.userName = consoleUI.getUserName();
			adminConsoleSharedObject.data.password = consoleUI.getPassword();
			adminConsoleSharedObject.flush();
		}

Newer Posts <-> Older Posts



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