在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 [email protected]
* @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接口 就可以了;