在我的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的更多相关文章

随机推荐

  1. MVC 区域模块

    mvc4.0新增的area区域机制,可以协助你在架构较为大型的项目,让独立性较高的部分功能独立成一个MVC子网站,以降低网站与网站之间的耦合性,也可以通过area的切割,让多人同时开发同一个项目时候, ...

  2. Linux下找不到动态链接库

    1.生成静态库 生成静态库使用ar工具,其实ar是archive的意思 $ar cqs libhello.a hello.o 2.生成动态库 用gcc来完成,由于可能存在多个版本,因此通常指定版本号: ...

  3. 给UIImage添加蒙版

    http://stackoverflow.com/questions/17448102/ios-masking-an-image-keeping-retina-scale-factor-in-acco ...

  4. this函数的理解

    Javascript的this用法 this是Javascript语言的一个关键字. 它代表函数运行时,自动生成的一个内部对象,只能在函数内部使用.比如, function test(){ this. ...

  5. js字母大小写转换

    function a(){ document.getElementById("test").value = document.getElementById("test&q ...

  6. EF加载实体的方式

    原文:Loading Related Entities EF加载数据的方式: 预加载 eager loading 延迟加载 lazy loading 显示加载 explicit loading 预先加 ...

  7. cookie 的Domain删除失败的问题

    最近接手一个老项目,项目中使用的是cookie来做的处理的,新增的时候cookie添加了域, 但是删除的时候没有添加域,导致删除cookie的时候一直失败!还有cookie的创建与删除,应该都必需经过 ...

  8. (转)union和union all的区别

    Union因为要进行重复值扫描,所以效率低.如果合并没有刻意要删除重复行,那么就使用Union All 两个要联合的SQL语句 字段个数必须一样,而且字段类型要“相容”(一致): 如果我们需要将两个s ...

  9. 对arm指令集的疑惑,静态库运行,编译报错等问题

    转载自http://www.jianshu.com/p/4a70aa03a4ea?utm_campaign=hugo&utm_medium=reader_share&utm_conte ...

  10. Java Se 基础系列(笔记) -- BasicDataType

    java.lang.String类代表不可变的字符序列 String类常用方法:1.public char charAt(int index); -- 返回下标为index的字符 2.public i ...