页面效果:
很多情况下,应用都是动态数据,需要根据左边的树点击后,动态设置右边参数.
Index.mxml代码如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600" xmlns:oneoper="com.gwtjs.oneoper.*" creationComplete="init()" xmlns:ns="http://hamcrest.org/2009/mxml" xmlns:runner="org.flexunit.runner.*">
<mx:Script>
<![CDATA[
import com.gwtjs.event.AddTabEvent;
import com.gwtjs.event.PublicTransferEvent;
import mx.collections.XMLListCollection;
import mx.controls.Alert;
import mx.core.Container;
import mx.core.UIComponent;
import mx.events.ListEvent;
import mx.events.TreeEvent;
import mx.rpc.events.ResultEvent;
[Bindable]
public static var selectedItem:Object = new Object();
[Bindable]
public var menuId:String;
[Bindable]
private var menus:XML;
private function LoadMenu(event:ResultEvent):void{
menus = XML(event.result);
var results:XMLList = menus.node;
tree.dataProvider = results;
}
private function ToFuncModule(event:ListEvent):void{
var url:String = '';
event.itemRenderer.data;
if(url!=null&&url!=""){
viewstack.selectedChild = Container(viewstack.getChildByName(url));
}
}
private function doListener(e:AddTabEvent):void{
Alert.show(e.url);
trace(e.url);
viewstack.selectedChild = Container(viewstack.getChildByName(e.url));
tree.expandChildrenOf(menus,true);
var metaTreeData:XMLListCollection = tree.dataProvider as XMLListCollection;
var treeNodes:XMLList=metaTreeData.descendants('menus');
for each(var treeNode:XML in treeNodes){
if([email protected]() == ""){
tree.selectedItem = treeNode;
tree.firstVisibleItem= treeNode;
break;
}
}
}
private function getChild(str:String):Object //这段代码是为了获得指定页面对应的对象
{
for each(var obj:Object in viewstack.getChildren()) //遍历vs中的所有子组件(即所有页面),页面不会太多,顶多一二十个,所以这个方法不会太耗时
{
if(obj.name === str) //如果是想找的页面,就返回这个对象。比如想找到welcome.mxml,则令str="welcome"
{
break;
}
}
return obj;
}
public function init():void{
selectedItem.id="1";
selectedItem.name="uq";
viewstack.selectedChild = Container(viewstack.getChildByName("A120000"));
this.dispatchEvent(new PublicTransferEvent(PublicTransferEvent.DOPARAMS,selectedItem));
menu.send();
menuId = "DD111"
getChild('A120000');
var obj:UIComponent = getChild('A120000') as UIComponent;
tree.doubleClickEnabled =true;
tree.addEventListener(AddTabEvent.CREATE_TAB_EVENT,doListener);
}
]]>
</mx:Script>
<mx:Model id="statesModel" source="assets/data/PageData.xml"/>
<mx:HTTPService url="assets/data/PageData.xml" id="menu" useProxy="false"
showBusyCursor="true" result="LoadMenu(event)" resultFormat="xml"/>
<mx:HDividedBox>
<mx:HBox>
</mx:HBox>
<mx:HDividedBox width="100%" height="100%" paddingRight="2" paddingLeft="2">
<mx:Tree id="tree" width="20%" height="100%" labelField="@label" />
<mx:Canvas width="79%" height="100%" id="canvas" label="{menuId}">
<mx:VBox width="100%" height="100%" paddingTop="5">
<mx:ApplicationControlBar height="46" width="100%" >
<mx:HBox width="100%" paddingTop="3">
<mx:Label text="Home" />
</mx:HBox>
</mx:ApplicationControlBar>
<mx:ViewStack id="viewstack" backgroundColor="#F2F3F8" width="100%" height="100%" cornerRadius="6" >
<oneoper:TPanel2 id="A121000" itemId="{selectedItem.id}"/>
<oneoper:TPanel1 id="A120000" cornerRadius="8" itemId="{selectedItem.id}"/>
<oneoper:TPanel3 id="A122000"/>
<oneoper:TPanel3 id="A123000"/>
</mx:ViewStack>
</mx:VBox>
</mx:Canvas>
</mx:HDividedBox>
</mx:HDividedBox>
</mx:Application>
<oneoper:TPanel2 id="A121000" itemId="{selectedItem.id}"/> --> TPanel1代码如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" creationComplete="init()">
<mx:Script>
<![CDATA[
import com.gwtjs.event.PublicTransferEvent;
import mx.containers.Canvas;
import mx.containers.ViewStack;
import mx.events.FlexEvent;
[Bindable]
public var item:Object;
[Bindable]
public var itemId:String;
public var _parent:Object;
public var ind:Index;
//13720353570 18907248366
public function eventListener(e:PublicTransferEvent):void{
this.addEventListener(PublicTransferEvent.DOPARAMS,eventListener);
var obj:Object = e.data;
trace(obj.id);
}
public function init():void{
trace(Index.selectedItem.id);
this.addEventListener(PublicTransferEvent.DOPARAMS,eventListener);
_parent = this.parent.parent.parent as Canvas;
trace(_parent.label);
itemId = _parent.label;
}
]]>
</mx:Script>
<mx:Label text="TPanel one {itemId}"/>
</mx:VBox>
需要在TPanel1里接到参数,然后根据参数去查询.TPanel1为自定义组件,传参数有点麻烦.最后解决办法如下看源码.
另一方法:
index.mxml:
隐藏一个表单
<mx:TextInput text="{bookIndex}" id="childTabIndex" visible="false" height="0" width="0" />
子页页面:
/**
* 初始化函数