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的更多相关文章
随机推荐
- SQL 使用经验
1. 写存储过程,Update数据库表,一定要根据idRow,也就是主键唯一键来更新. 更新操作,如果根据其他条件更新,之后就有的忙活了. 2. Query语句要加NOLOCK
- javascript对象的理解
从代码中体会javascript中的对象: <!DOCTYPE html> <html> <head> <meta charset="utf-8&q ...
- 使用MutationObserver对象封装一个监听DOM生成的函数
(function(win){ 'use strict'; var listeners = []; var doc = win.document; var MutationObserver = win ...
- C++11 多线程 基础
C++11开始支持多线程编程,之前多线程编程都需要系统的支持,在不同的系统下创建线程需要不同的API如pthread_create(),Createthread(),beginthread()等,使用 ...
- 查看linux版本和内核信息
一.查看Linux内核版本命令(两种方法): 1.cat /proc/version [root@localhost ~]# cat /proc/versionLinux version 2.6.32 ...
- MVC笔记
简要论述对MVC模式的理解,并简述ThinkPHP中的MVC模式是如何运行的 MVC(Model-View-Controller)应用程序结构被用来分析分布式应用程序的特征.这种抽象结构能有助于将应用 ...
- 《第一行代码》学习笔记6-活动Activity(4)
1.SecondActivity不是主活动,故不需要配置标签里的内容. 2.Intent是Android程序中各组件之间进行交互的一种重要方式,一般可被用于 启动活动,启动服务,以及发送广播等.Int ...
- Visifire Chart控件设置 柱状图 条的宽窄
Chart myChart = new Chart();myChart.DataPointWidth = 5;宽度以PlotArea的百分比为单位,如下例: chart.Width = 500; c ...
- C#串口扫描
1.传入serialport 和待显示串口的Commbox private void Search_AddSerialToComboBox(SerialPort MyPort, ComboBox My ...
- 【android】android下的junit
<instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPa ...