Flex State的用法

1.State用来控制页面间的切换:
<s:states>
 <s:State name="add" />
 <s:State name="list" />
</s:states>


它使用view.currentState="add" 或者
view.currentSate="list"来切换页面。

 

add表示新建页面,list表示列表页面。

<s:HGroup width="100%" height="30" verticalAlign="middle" paddingLeft="5" excludeFrom="add,view">
excludeFromas表示不包含在add或者view页面。
<s:VGroup width="100%" height="100%" includeIn="add" horizontalAlign="center" >
inCludeIn表示包含在add页面。


<s:Panel width="100%" height="100%" title.add="新建角色" title.view="查看角色"  >


IPM-481
<s:HGroup  verticalAlign="middle" paddingLeft="5" width="100%" height.add="45%" height.view="0" >


2.如何在一个组件中调用另一个组件

方法一:
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
   xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="init()"
   xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%" 
  
   xmlns:component="com.view.component.*"
   remove="destroy()">
 

//组件调用:RoleConfigView是com.view.component.RoleConfigView.mxml  定义id来操作它里面的组件
 <component:RoleConfigView width="100%" height="100%" includeIn="view" id="roleView"/>
</s:Group>

private function init():void{
 //初始化所有的组件
 this.currentState='add';
 this.currentState='view';
 this.currentState='list'; //最后初始化list,这个state.显示状态的页面
}


方法二:
页面:
facade.sendNotification(RoleNotification.INITADD_PANEL, this);

Mediator:
 override public function handleNotification(notification:INotification):void
  {
   switch (notification.getName())
   {
    case MonitoringModelNotification.INIT_ADD_PANEL:
     this.initAddPanel();
     break;

   }
  }

private function initAddPanel():void{
var panel:RoleConfigView = this.getViewComponent() as RoleConfigView;

}

 

13.basedOn 继承另一个状态的组件
<s:states>
 <s:State name="old"/>
 <s:State name="newOld" basedOn="old"/>
</s:states>

<mx:State name="login" enterState="loginEnter(event)" exitState="loginExit(event)">
进入login状态,执行loginEnter(event),退出login状态,执行loginExit(event)

private function loginEnter(event:FlexEvent):void{
 this.addChild(new Main());  //增加子模块
}
private function loginExit(event:FlexEvent):void{
 this.removeAllChildren(); //移除所有的组件
}

你可能感兴趣的:(xml,Flex,Adobe)