+展开-ActionScript
package oreilly.cookbook {
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
public class ComplexDataType extends EventDispatcher {
public static const NAME_CHANGED:String = "nameChanged" ;
public static const OFFICE_CHANGED:String = "officeChanged" ;
public static const RECORD_CHANGED:String = "recordChanged" ;
private var _name:Name;
private var _office:Office;
private var _label:String;
public function ComplexDataType(target:IEventDispatcher=null ) {
super(target);
}
[Bindable(RECORD_CHANGED)]
public function set label(value:String):void {
_label = value;
dispatchEvent(newEvent(RECORD_CHANGED));
}
public function get label():String { return _label; }
[Bindable(NAME_CHANGED)]
public function set name(value:Name):void {
_name = value;
dispatchEvent(newEvent(NAME_CHANGED));
}
public function get name():Name { return _name; }
[Bindable(OFFICE_CHANGED)]
public function set office(value:Office):void {
_office = value;
dispatchEvent(newEvent(OFFICE_CHANGED));
}
public function get office():Office { return _office; }
}
}
+展开-ActionScript
package oreilly.cookbook {
import mx.collections.ArrayCollection;
import mx.collections.ICollectionView;
import mx.controls.treeClasses.ITreeDataDescriptor;
public class ComplexDataCollection implements ITreeDataDescriptor {
public function getChildren(node:Object,model:Object=null):ICollectionView{
var col:ArrayCollection;
if(node is Office){
col = newArrayCollection([node.officeAddress,node.officeName]);
return col;
}
if (node is Name){
col = new ArrayCollection([node.firstName, node.lastName]);
return col;
}
if (node is ComplexDataType){
col = new ArrayCollection([node.office, node.name]);
return col;
}
return null ;
}
public function hasChildren(node:Object, model:Object=null ):Boolean {
if (node is Office){
if (node.officeAddress != "" && node.officeName != "" ){
return true ;
} else {
return false ;
}
}
if (node is Name){
if (node.firstName != "" && node.firstName != "" ){
return true ;
} else { return false ; }
}
if (node is ComplexDataType){
if (node.office != null && node.name != null ) {
return true ;
} else { return false ; }
}
return false ;
}
public function isBranch(node:Object, model:Object=null ):Boolean {
if (node is Office){
if (node.officeAddress != "" && node.officeName != "" ){
return true ;
} else {
return false ;
}
}
if (node is Name) {
if (node.firstName != "" && node.firstName != "" ){
return true ;
} else {
return false ;
}
}
if (node is ComplexDataType) {
if (node.office != null && node.name != null ) {
return true ;
} else { return false ;
}
}
return true ;
}
public function getData(node:Object, model:Object=null ):Object {
if (node is Office) {
return {children:{label:node.officeName, label:node.officeAddress}};
}
if (node is Name) {
return {children:{label:node.firstName, label:node.lastName}};
}
if (node is ComplexDataType){
return {children:{label:node.office, label:node.name}};
}
return null ;
}
public function addChildAt(parent:Object, newChild:Object, index:int,model:Object=null):Boolean {
return false ;}
public function removeChildAt(parent:Object, child:Object, index:int,model:Object=null):Boolean {
return false ;
}
}
}