Reputation: 4246
I need a method to disable user interaction with the application for certain calls to a server for information. I've been using the following code to disable/enable the application before/after the server call. Basically, it gives the user a busy cursor and disables the application while the call is being processed on the server.
When the call from the server is submitted, I execute:
CursorManager.setBusyCursor();
mx.core.FlexGlobals.topLevelApplication.enabled=false;
When the call from the server returns, I execute:
CursorManager.removeBusyCursor();
mx.core.FlexGlobals.topLevelApplication.enabled=true;
This has the problem that the application color dims. Is there a way to prevent it from dimming? Alternatively, can I disable the mouse click and keyboard somehow? Or, what do other people do in this situation?
Upvotes: 0
Views: 3247
Reputation: 21
here is a simple soution:-
protected static function toggleScreenClick (value : Boolean) : void
{
if (value)
{
FlexGlobals.topLevelApplication.setStyle("disabledOverlayAlpha", 0.5);
}
else
{
FlexGlobals.topLevelApplication.setStyle("disabledOverlayAlpha", 0.0);
}
FlexGlobals.topLevelApplication.enabled = value;
}
Upvotes: 0
Reputation: 181
What works for me...
private var _lastFocusedElement:InteractiveObject;
private function set enabled(value:Boolean):void {
value ? CursorManager.removeBusyCursor(): CursorManager.setBusyCursor();
var stage:Stage = FlexGlobals.topLevelApplication.stage;
if (stage) {
stage.mouseChildren = value;
stage.tabChildren = value;
if (!value)
_lastFocusedElement = stage.focus;
stage.focus = value ? _lastFocusedElement : null;
}
}
Regards, Vjeko
Upvotes: 1
Reputation: 4367
I have an AMFConnector class that makes all my calls. Every time that this class will make a call, it sets the cursor to Busy Mode and sets a boolean property to true (amf_busy). All my application is built to use that property to active/desactive buttons that makes calls/commands. Your solution is faster and easier, but as you stated, it fades the whole screen and it's not very user-friendly. Now as the user sees that when he made an action, just the buttons fades, he's automatically aware that he now has to wait the server to come back with an answer, even though he doesn't understand client-server calls.
Edit: As to disable mouse/keyboard, it's not very user-friendly either. You have to be careful with the user profile if you go with that solution. It is likely that the user will see that 'sometimes' the keyboard/mouse stops to work 'for apparently no reason' since he doesn't understand what's happening.
Edit II: Since I don't know how BlazeDS works, I will use my own example and you might try to translate it.
This is how a simple call would look like:
//creating a object connection.
var gateway:NetConnection = new Netconnection();
//connect
gateway.connect(url_connection_here);
//Making a simple call
gateway.call("UserController/GetUser", new Responder(onResult, onfault));
This is what you would do:
Create a gateway to receive the calls:
[Bindable] public class AMFConnctor{
private var instance:AMFConnector = new AMFConnector();
public function getInstance():AMFConnector{
return instance;
}
public function AMFConnector(){
if(instance){
throw new Error("Singleton class cannot be instanced. Use getInstance() method instead.");
}
}
private var _amf_busy:Boolean = false;
public function get amf_busy():Boolean{
return _amf_busy;
}
public function set amf_busy(value:Boolean):void{
//If you are setting to true (yes, it's busy)
if(value){
CursorManager.setBusyCursor();
_amf_busy = true;
}else{
_amf_busy = false;
CursorManager.removeBusyCursor();
}
}
//Here I assume that everytime that I ask this class for the gateway
//it's because I'm going to make a call, which means that I want the
//rest of the application knows that AMF is currently busy.
public function get Gateway():NetConnection{
amf_busy = true;
return this._gateway;
}
}
If you have a gateway similarly like this, you can now easily configure your buttons:
<mx:Button id="btnSubmit1" label="Submit" click="action" icon="@Embed(source='images/ok.png')" enabled="{!AMFConnector.getInstance().amf_busy}"/>
<mx:Button id="btnCancel1" label="Cancel" click="action" icon="@Embed(source='images/cancel.png')" enabled="{!AMFConnector.getInstance().amf_busy}"/>
Now, the only thing that you have to make sure is that inside your 'onResult' functions, the ones that will be called after the Server Side returns your call, you have to make sure to set the amf_busy property to Off (false) and that will automatically enable back all the buttons.
Upvotes: 1
Reputation: 3961
Try:
// in your method
const stage:Stage = mx.core.FlexGlobals.topLevelApplication.stage;
if (stage)
stage.mouseChildren = false; // or true of course
Upvotes: 3