Calling Application.application.enable from a TitleWindow in a different mxml component

自古美人都是妖i 提交于 2019-12-24 16:19:50

问题


Good day.

I have a Flex RIA App, and in the application tag there is a button when its pressed calls upon a TitleWindow from another .mxml file, and sets

application.enable = false

That way the user cant use any of the components in the application, and still can use the components in the TitleWindow.

The problem its. When the TitleWindow is close i want him to restore the application back to

application.enable = true

Wich enables the application once again. But i can't call that code from inside the TitleWindow .mxml

How can i do it?..

Here is the Source:

Loja.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="585" height="450" xmlns:ns1="com.*">
<mx:Style source="theme/simplicitygray.css" />

    <mx:Script>
        <![CDATA[
            import mx.managers.PopUpManager;
            private var clientid = 0;       

            public function openWindow() : void
            {
                if (clientid == 0) 
                {
                    PopUpManager.createPopUp(this,Login,false);
                    application.enabled = false;
                } else {
                    PopUpManager.createPopUp(this,Conta,false);
                    application.enabled = false;
                }
            }
        ]]>
    </mx:Script>

    <mx:Panel x="10" y="40" width="565" height="400" layout="absolute">
    </mx:Panel>
    <mx:MenuBar x="10" y="10" width="565" height="22"></mx:MenuBar>
    <mx:Button x="508" y="10" label="Aceder" click="openWindow();"/>

</mx:Application>

And one of the title windows. Once they are the same.

Login.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="350" height="200" creationComplete="centerWindow()" showCloseButton="true" close="closeWindow()" title="Login">

    <mx:Script>
        <![CDATA[
            import mx.managers.PopUpManager;
            public function centerWindow():void
            {
                PopUpManager.centerPopUp(this);
            }

            public function closeWindow():void
            {
                PopUpManager.removePopUp(this);

            }

       ]]>

    </mx:Script>

</mx:TitleWindow>

Any help is greattly apreciated. Thanks.


回答1:


application is a static property of the Application class and can be called from the TitleWindow

public function closeWindow():void
{
    PopUpManager.removePopUp(this);
    Application.application.enabled = true;
}

BTW, There is another easier way to achieve the following:

That way the user cant use any of the components in the application, and still can use the components in the TitleWindow.

That is to use a modal popup. Set the third parameter of the createPopUp to true and that's it - you don't have to enable/disable the application manually: flex will take care of it.

PopUpManager.createPopUp(this,Login, true);

application will automatically become functional once you call removePopUp.




回答2:


You can use custom events to enable this functionality, as described here.

Essentially, you set up a custom event in the class you are calling, then create a function that runs when the event is consumed. That way your 'Loja' will know when the 'Login' is done.



来源:https://stackoverflow.com/questions/1451618/calling-application-application-enable-from-a-titlewindow-in-a-different-mxml-co

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!