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的更多相关文章
随机推荐
- 《Learn python the hard way》Exercise 48: Advanced User Input
这几天有点时间,想学点Python基础,今天看到了<learn python the hard way>的 Ex48,这篇文章主要记录一些工具的安装,以及scan 函数的实现. 首先与Ex ...
- js基础例子dom+原型+oop基础知识记录01
//oo:概念是计算机中对于现实世界的理解和抽象的方法 //由计算机利用编程技术发展到现在的产物 //面向对象几要素 //对象:由属性和方法组成的集合 //属性:保存数据,存储在对象内存空间中的唯一的 ...
- (转)Android’s HTTP Clients
转载自:http://android-developers.blogspot.com/2011/09/androids-http-clients.html Most network-connected ...
- eclipse 中 maven3 创建web项目
一.创建项目 1.Eclipse中用Maven创建项目 上图中Next 2.继续Next 3.选maven-archetype-webapp后,next 4.填写相应的信息,Packaged是默认创建 ...
- 浅谈GitLab与Git
前言:先解释下关于库的认识. Workspace:工作区 Index / Stage:暂存区 Repository:仓库区(或本地仓库) Remote:远程仓库 一.新增项目(远程仓库) 在GitLa ...
- [CSAPP笔记][第十一章网络编程]
第十一章 网络编程 我们需要理解基本的客户端-服务端编程模型,以及如何编写使用因特网提供的服务的客户端-服务端程序. 最后,我们将把所有这些概念结合起来,开发一个小的但功能齐全的Web服务器,能够为真 ...
- 常见HTTP状态码的含义
200 请求已成功,请求所希望的响应头或数据体将随此响应返回. 301 被请求的资源已永久移动到新位置. 302 请求的资源现在临时从不同的 URI 响应请求. 400 1.语义有误,当前请求无法被服 ...
- .NET基础拾遗(3)字符串、集合和流1
一.字符串处理 1.1 StringBuilder类型 众所周知,在.NET中String是引用类型,具有不可变性,当一个String对象被修改.插入.连接.截断时,新的String对象就将被分配,这 ...
- compass模块
Compass核心模块Reset :重置CSS模块 @import "compass/reset" Layout :页面布局的控制能力 @import "compass/ ...
- (转)Div+CSS布局入门
在网页制作中,有许多的术语,例如:CSS.HTML.DHTML.XHTML等等.在下面的文章中我们将会用到一些有关于HTML的基本知识,而在你学习这篇入门教程之前,请确定你已经具有了一定的HTML基础 ...