FlexComboBoxTree
在我的CSDN资源中有项目工程文件。下载导入工程即可看到效果,下面是地址。
http://download.csdn.net/detail/cym_lmy/6326053
MyCombBoxTree1.as
package com.cym
{
import flash.events.MouseEvent;
import flashx.textLayout.events.ScrollEvent;
import mx.collections.IList;
import mx.controls.Alert;
import mx.controls.Tree;
import mx.events.ListEvent;
import mx.managers.PopUpManager;
import spark.components.ComboBox;
import spark.events.DropDownEvent;
public class MyCombBoxTree1 extends ComboBox
{
private var _tree:Tree;
private var __dataProvider:IList;
private var _dropDownWidth:int;
public var _dropDownHeight:int;
public var xzqhbm:String;
public var xzqhbmField:String;
override protected function createChildren():void {
addEventListener(DropDownEvent.OPEN, dropDownControllerOpenHandler);
addEventListener(DropDownEvent.CLOSE, dropDownControllerCloseHandler);
super.createChildren();
}
override public function set dataProvider(value:IList):void {
__dataProvider = value;
}
private function dropDownControllerOpenHandler(event:DropDownEvent):void {
if (!_tree) {
_tree = new Tree();
}
_tree.dataProvider = __dataProvider;
_tree.labelField = this.labelField;
_tree.width = _dropDownWidth ? _dropDownWidth : this.width;
_tree.height = _dropDownHeight ? _dropDownHeight : 150;
popUpTree();
StopLisentEventHandle();
}
public function dropDownControllerCloseHandler(event:DropDownEvent):void {
if (this._tree) {
PopUpManager.removePopUp(this._tree);
this.textInput.text = this._tree.selectedItem ? this._tree.selectedItem[this._tree.labelField] : '';
xzqhbm = this._tree.selectedItem ? this._tree.selectedItem[xzqhbmField] : '';
var treeboxevent:TreecomboboxEvent = new TreecomboboxEvent(xzqhbm);
this.dispatchEvent(treeboxevent);
}
}
override protected function dropDownController_closeHandler(event:DropDownEvent):void
{
if(_tree.selectedItem){
StartLisentEventHandle();
super.dropDownController_closeHandler(event);
}
}
/**
* 定位弹出窗口
*
*/
private function popUpTree():void {
this._tree.x = this.dropDownController.dropDown.x;
this._tree.y = this.dropDownController.dropDown.y;
PopUpManager.addPopUp(this._tree, this);
}
/**
* 停止对事件流中当前节点中和所有后续节点中的事件侦听器进行处理。
* */
private function StopLisentEventHandle():void {
this.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void {
e.stopImmediatePropagation();
});
this.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent):void {
e.stopImmediatePropagation();
});
this.addEventListener(MouseEvent.MOUSE_WHEEL, function(e:MouseEvent):void {
e.stopImmediatePropagation();
});
_tree.addEventListener(MouseEvent.MOUSE_WHEEL, function(e:MouseEvent):void {
e.stopImmediatePropagation();
});
}
/**
* 恢复对事件流中当前节点中和所有后续节点中的事件侦听器进行处理。
* */
private function StartLisentEventHandle():void {
this.removeEventListener(MouseEvent.CLICK, function(e:MouseEvent):void {
e.stopImmediatePropagation();
});
this.removeEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent):void {
e.stopImmediatePropagation();
});
this.removeEventListener(MouseEvent.MOUSE_WHEEL, function(e:MouseEvent):void {
e.stopImmediatePropagation();
});
_tree.removeEventListener(MouseEvent.MOUSE_WHEEL, function(e:MouseEvent):void {
e.stopImmediatePropagation();
});
}
private function set dropDownHeight(value:int):void {
this._dropDownHeight = value;
}
public function MyCombBoxTree1()
{
super();
}
}
}
TreecomboboxEvent.as
package com.cym
{
import flash.events.Event;
public class TreecomboboxEvent extends Event
{
public static const NAME:String="treecomboboxevent";
private var _data:Object;
public function TreecomboboxEvent(data:Object=null)
{
super(NAME, false, false);
this._data=data;
}
public function get data():Object
{
return _data;
}
public function set data(value:Object):void
{
_data = value;
}
}
}
测试
<?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:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600"
xmlns:cym="com.cym.*"
creationComplete="loadXML()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import com.cym.TreecomboboxEvent;
import mx.collections.ArrayCollection;
import mx.collections.XMLListCollection;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
public var xmlService:HTTPService = new HTTPService();
[Bindable]
public var xmlResult:XML;
[Bindable]
public var xmlList:XMLList;
[Bindable]
public var xmlTeams:XMLListCollection;
public function loadXML():void
{
xmlService.url = "mlb.xml"
xmlService.resultFormat = "e4x";
xmlService.addEventListener(ResultEvent.RESULT, resultHandler);
xmlService.send();
}
public function resultHandler(event:ResultEvent):void
{
xmlResult = XML(event.result);
xmlList = xmlResult.children();
xmlTeams = new XMLListCollection(xmlList);
cg.addEventListener(TreecomboboxEvent.NAME,ceshi);
}
public function ceshi(event:TreecomboboxEvent):void{
haha.text=event.data.toString();
}
]]>
</fx:Script>
<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
@namespace cym "com.cym.*";
mx|Tree{
defaultLeafIcon:ClassReference(null);
folderOpenIcon:ClassReference(null);
folderClosedIcon:ClassReference(null);
}
</fx:Style>
<mx:HBox>
<cym:MyCombBoxTree1 id="cg" dataProvider="{xmlTeams}" labelField="@label" _dropDownHeight="200" xzqhbmField="@id"/>
<s:TextInput id="haha"/>
</mx:HBox>
</s:Application>
FlexComboBoxTree的更多相关文章
随机推荐
- linux文件系统学习
linux系统支持很多种文件系统. 1. 如何确认当前系统挂载了哪些文件系统? 使用mount命令可以查看当前系统上已经挂载了哪些文件系统, sh-# mount rootfs on / type r ...
- centerOS安装rkhunter
rkhunter是专业检测系统是否感染rootkit的一个工具: rkhunter-1.4.2.tar.gz 解压后直接安装: #./installer.sh --layout defualt --i ...
- iOS 部分问题总结2 - 苹果审核篇
iOS 部分问题总结(二) - 苹果审核篇 1. 记录下5.1新规后上传被拒的问题排查和解决过程. 几天前,最新一次的更新被拒了,提示Invaild Binary.好在苹果同时发来了说明邮件做了详细说 ...
- 在sae配置django项目
1:使用sae开发必须有sae帐号,自己注册吧: 2:在sae上新建立一个python项目: 3:建立完成之后新建一个版本,即版本1: 4:获取svn的地址在eclipse中check下来: 5:注意 ...
- gnuplot常用技巧
一. 基础篇: 在linux命令提示符下运行gnuplot命令启动,输入quit或q或exit退出. 1.plot命令 gnuplot> plot sin(x) with l ...
- linux 服务器更主板后无法识别网卡处理过程
linux 服务器更主板后无法识别网卡处理过程 服务器故障报修,主板坏,更换主板后无法识别网卡,ifconfig 查看只显示:lo loopback 127.0.0.1. 系统加载网卡驱动后会去读 ...
- ASP.NET中实现Ajax分页
在页面中指定一个div容器来接收动态生成的分页数据: <div id="div_menu"> </div> 使用jQuery来请求并处理Json格式数据: ...
- Java 访问控制符
Java提供了3个访问控制符:private.protected和public,分别代表了3个访问控制级别,另外还有一个不加任何访问控制符的访问控制级别,提供了4个访问控制级别.Java的访问控制级别 ...
- mysql忘记密码的处理方式(整理非原创)
方案1.通过跳过授权的方式 1.修改MySQL的登录设置: # vi /etc/my.cnf 在[mysqld]的中加上:skip-grant-tables . 2.重新启动mysqld # ubun ...
- HTML5画布(圆形)
案例1: <!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8& ...