0

我正在用 flex 开发一个桌面空气应用程序。我有 2 个 mxml (一个 mxml 是 windowedapplication,另一个是 mxml 组)。我想从一个 mxml 文件 ( login.mxml) 导航到另一个 ( nextpage.mxml)。

我怎样才能做到这一点?

登录.mxml:

<?xml version="1.0" encoding="utf-8"?><s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>`enter code here`
<![CDATA[
public function onLogin()
{
// What code should i use to navigate to another mxml page i.e nextpage.mxml
}
]]>
</fx:Script><s:Button id="btn" name="Login" click="onLogin()"/</s:WindowedApplication>

下一页.mxml:

<?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" 
     xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Label text="Login Success/></s:Group>
4

1 回答 1

0

将主应用程序实现为应用程序状态的协调器会很好。

在这种情况下,您可以使用 ViewStack 组件,该组件具有 Login 和 NextPage 组件作为子组件。组件通过事件与应用程序通信。根据当前事件,状态会发生变化。

//主应用

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s="library://ns.adobe.com/flex/spark" 
                   xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:fld01="com.fld01.*">

<mx:ViewStack id="vsMain">
    <s:NavigatorContent id="ncLogin">
        <fld01:Login id="grLogin" evtLogin="{vsMain.selectedChild = ncNextPage}"/>
    </s:NavigatorContent>

    <s:NavigatorContent id="ncNextPage">
        <fld01:Nextpage id="grNextPage" evtLogout="{vsMain.selectedChild = ncLogin}"/>
    </s:NavigatorContent>
</mx:ViewStack>

</s:WindowedApplication>

//登录

<?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" 
     xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">

<fx:Metadata>
    [Event(name="evtLogin", type="flash.events.Event")]
</fx:Metadata>

<fx:Script>
    <![CDATA[
        public function onLogin():void
        {
            this.dispatchEvent(new Event("evtLogin"));  
        }
    ]]>
</fx:Script>

<s:Button id="btn" x="40" y="50" label="Login" click="onLogin()"/>
</s:Group>

//下一页

<?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" 
     xmlns:mx="library://ns.adobe.com/flex/mx" 
     width="400" height="300">

<fx:Metadata>
    [Event(name="evtLogout", type="flash.events.Event")]
</fx:Metadata>

<fx:Script>
    <![CDATA[
        public function onLogout():void
        {
            this.dispatchEvent(new Event("evtLogout")); 
        }
    ]]>
</fx:Script>

<s:Label x="40" y="50" text="Login Success"/>

<s:Button id="btn" x="40" y="80" label="Logout" click="onLogout()"/>

</s:Group>
于 2013-06-25T16:10:55.790 回答