tags:

views:

611

answers:

2

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  A: 

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.

Michael Todd
Right i was trying to do a event listener to watch for the TitleWindow exit, but no luck. Any way Amarghosh last method proved simple and effective. Any way thanks Michael.
Fábio Antunes
+2  A: 

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.

Amarghosh
Lool.. You can't imagine how much i've been wondering and trying to do this... and a simple true does the trick.. lol.. Thanks.
Fábio Antunes
Hey thanks, was looking for this solution too! :)Helped me out.
Jakub