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的更多相关文章
随机推荐
- 一个session已经ACTIVE20多小时,等待事件SQL*Net more data from client
问题描述: 一个session已经ACTIVE20多小时,等待事件SQL*Net more data from client 有一人session,从昨天上午11点多登陆(v$session.logi ...
- C/C++基础概念
1.类占用的内存大小: 1)在不同位数的操作系统下,各种数据类型所占用的内存大小:32位和64位操作系统 http://blog.csdn.net/b_zhang/article/details/68 ...
- cocos2d-x 3.6版连连看
写个连连看来讲游戏开发,我认为实例解说效果会好一些. 终端以下cd到源代码文件夹,敲命令: cocos new LLK -p com.goonear.llk -l cpp -d ./Goonear 脚 ...
- Property与Attribute的区别
Property属于面向对象的范畴----属性 Attribute则是编程语言文法层面的东西----特征 Property属于面向对象的范畴.在使用面向对象编程的时候,常常需要对客观 ...
- 《第一行代码》学习笔记3-活动Activity(1)
1.活动-一种可以包含用户界面的组件,用于和用户进行交互. <Button android:id="@+id/button_1" android:layout_width=& ...
- CSS 设计模式一 元素
1.background 内置 是一种CSS内置设计模式,支持在元素下显示图片 HTML <!DOCTYPE html> <html lang="en"> ...
- SSM框架搭建web服务器实现登录功能(Spring+SpringMVC+Mybatis)
初学java EE,虽然知道使用框架会使开发更加便捷高效,但是对于初学者来说,感到使用框架比较迷惑,尤其是各种jar包的引用.各种框架的配置.注解的使用等等. 最好的学习方法就是实践,于是下载了一个现 ...
- DataSource
数据库连接池原理:在内存中开辟一段存储空间用来存储多个Connection连接,避免频繁的创建Connection,从而提高效率.代码如下: package jcbc.ds.test1; import ...
- hdu4497 正整数唯一分解定理应用
C - (例题)整数分解,计数 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65535KB ...
- poj3614 贪心
Sunscreen Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6410 Accepted: 2239 Descrip ...