我想使用延迟加载创建动态树,每次打开文件夹时树都会向服务器发送http请求,在此脚本中我只使用静态文本来测试树,但是,我&# 39;在根目录的标签中获取分配给数据提供者的所有XML文本,然后当我打开根文件夹时,我得到了具有良好标签的孩子,并且openitem和closeitem事件不会触发我怎么能让它们工作,任何欢迎帮助
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import mx.collections.XMLListCollection;
import mx.events.ListEvent;
var origXML:XML;
public function initList()
{
//tree.rootVisible = false;
//TODO: Get this XML from a data service
var origXMLString:String = "<node isBranch=\"true\"><node>supernode1</node>" +
"<node>supernode2</node>" +
//"<node label=\"supernode2\" someProp=\"sdsdf \" isBranch=\"true\"/></node>" +
//"<node label=\"supernode3\" someProp=\"sdsdf \" isBranch=\"true\"/></node>" +
"</node>";
origXML = new XML(origXMLString);
tree.dataProvider = origXML;
}
public function open(event:Object)
{
var selectedNode:Object = event.node;
var myXMLList:XMLList = new XMLList(selectedNode);
//TODO: Get this XML from a data service based on the selected node.
var newXMLString:String = "<childnode1 label=\"childnode1\" someProp=\"sdsdf \" isBranch=\"true\" />" +
"<childnode2 label=\"childnode2\" someProp=\"sdsdf \" isBranch=\"false\" />" +
"<childnode3 label=\"childnode3\" someProp=\"sdsdf \" isBranch=\"true\" />" ;
var myNewXMLList:XMLList = new XMLList(newXMLString);
selectedNode.setChildren(myNewXMLList);
/* myText1.text = selectedNode.toXMLString();
myText2.text = myTree.dataProvider.source[0]; */
tree.dataProvider = origXML;
}
public function close(event:Object)
{
var selectedNode:Object = event.node;
var myXMLList:XMLList = new XMLList(selectedNode);
removeAllDecendants(myXMLList);
/* myText1.text = selectedNode.toXMLString();
myText2.text = myTree.dataProvider.source[0]; */
tree.dataProvider = origXML;
}
public function removeAllDecendants(xmlList:XMLList)
{
var myDescendantXMLList:XMLList = xmlList.descendants();
var myDecendentXMLListCollection:XMLListCollection = new XMLListCollection(myDescendantXMLList);
myDecendentXMLListCollection.removeAll();
}
private function send_data():void {
var loader : URLLoader = new URLLoader();
var request : URLRequest = new URLRequest("http://localhost/index.php" );
// pass the post data
request.method = URLRequestMethod.POST;
var variables : URLVariables = new URLVariables();
variables.s = "haha";
request.data = variables;
// add handlers
loader.addEventListener(Event.COMPLETE, on_complete);
loader.load(request);
// userRequest.send();
}
private function on_complete(e : Event):void{
}
]]>
</fx:Script>
<mx:Tree id="tree" x="103" y="49" width="445" height="278" enabled="true"
itemClose="close(event)" itemOpen="open(event)" selectedIndex="1"></mx:Tree>
答案 0 :(得分:2)