加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

关于flex中IMXMLObject的一点心得

发布时间:2020-12-15 01:03:03 所属栏目:百科 来源:网络整理
导读:??? 在flex中可以通过IMXMLObject的实现来达到对纯as3类的mxml显示支持;以前没怎么了解过 今天看了下 感觉用起来还是很方便; 其实非常简单 只需要把你自己的类实现IMXMLObject 接口就可以了 。 比如: //////////////////////////////////////////////////

??? 在flex中可以通过IMXMLObject的实现来达到对纯as3类的mxml显示支持;以前没怎么了解过 今天看了下 感觉用起来还是很方便;

其实非常简单 只需要把你自己的类实现IMXMLObject 接口就可以了 。

比如:

////////////////////////////////////////////////////////////////////////////////
// WEBGAME Confidential 
// Copyright 2011. All rights reserved. 
// 
// Remote.as
// Summary // TODO Auto-generated summary stub
// Version 1.0
// Author txiejun
// Created Nov 24,2011 5:30:29 PM
////////////////////////////////////////////////////////////////////////////////
package com
{
	import flash.display.Sprite;
	import flash.events.Event;
	
	import mx.core.IMXMLObject;

	[Event(name="result",type="flash.events.Event")]
	/**
	 *
	 * @author txiejun
	 * @contact txiejun@126.com
	 * @created Nov 24,2011 5:30:29 PM
	 */
	public class Remote extends Sprite implements IMXMLObject
	{
		private var document:Object;
		private var id:String;
		public function Remote()
		{
			super();
		}
		
		public function initialized(document:Object,id:String):void
		{
			this.document = document;
			this.id = id;
			this.dispatchEvent(new Event("result"));
		}
	}
}

需要注意的就是事件处理:需要写类似于这样的代码:

[Event(name="result",type="flash.events.Event")]

这样就可以在mxml标签中直接通过提示打出来你想要的result事件标识了;

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" xmlns:com = "com.*"
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

	<fx:Script>
		<![CDATA[
			protected function rt_resultHandler(event:Event):void
			{
				// TODO Auto-generated method stub
			}
		]]>
	</fx:Script>

	<fx:Declarations>
		<!-- Place non-visual elements (e.g.,services,value objects) here -->
		<com:Remote id="rt" result="rt_resultHandler(event)"/>
	</fx:Declarations>
</s:Application>
同理的 如果想要把你自己的类变成一个flexUI编辑器可以识别的并且在components的custom栏可以显示出来的组件 只需要实现IVisualElement接口 就可以了;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读