Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 Flex:如何在服务器调用期间禁用用户与应用程序的交互?_Actionscript 3_Apache Flex - Fatal编程技术网

Actionscript 3 Flex:如何在服务器调用期间禁用用户与应用程序的交互?

Actionscript 3 Flex:如何在服务器调用期间禁用用户与应用程序的交互?,actionscript-3,apache-flex,Actionscript 3,Apache Flex,我需要一种方法来禁用用户与应用程序的交互,以便对服务器进行某些调用以获取信息。我一直在使用以下代码在服务器调用之前/之后禁用/启用应用程序。基本上,它给用户一个忙碌的游标,并在服务器上处理呼叫时禁用应用程序 提交来自服务器的调用时,我执行: CursorManager.setBusyCursor(); mx.core.FlexGlobals.topLevelApplication.enabled=false; CursorManager.removeBusyCursor(); mx.cor

我需要一种方法来禁用用户与应用程序的交互,以便对服务器进行某些调用以获取信息。我一直在使用以下代码在服务器调用之前/之后禁用/启用应用程序。基本上,它给用户一个忙碌的游标,并在服务器上处理呼叫时禁用应用程序

提交来自服务器的调用时,我执行:

CursorManager.setBusyCursor(); 
mx.core.FlexGlobals.topLevelApplication.enabled=false;
CursorManager.removeBusyCursor(); 
mx.core.FlexGlobals.topLevelApplication.enabled=true;
当来自服务器的调用返回时,我执行:

CursorManager.setBusyCursor(); 
mx.core.FlexGlobals.topLevelApplication.enabled=false;
CursorManager.removeBusyCursor(); 
mx.core.FlexGlobals.topLevelApplication.enabled=true;
这存在应用程序颜色变暗的问题。有没有办法防止它变暗?或者,我可以以某种方式禁用鼠标单击和键盘吗?或者,其他人在这种情况下会怎么做?

试试:

// in your method
const stage:Stage = mx.core.FlexGlobals.topLevelApplication.stage;
if (stage)
  stage.mouseChildren = false; // or true of course
尝试:


我有一个AMFConnector类,可以进行所有调用。每次此类进行调用时,都会将光标设置为忙模式,并将布尔属性设置为true(amf_Busy)。我的所有应用程序都是使用该属性来激活/取消激活按钮来进行调用/命令的。 您的解决方案更快、更简单,但正如您所说的,它会使整个屏幕褪色,对用户不是很友好。现在,当用户看到当他做出一个动作时,按钮就会消失,他会自动意识到他现在必须等待服务器返回一个答案,即使他不理解客户端-服务器调用

编辑: 至于禁用鼠标/键盘,它也不是很友好。如果使用该解决方案,您必须小心使用用户配置文件。用户可能会看到“有时”键盘/鼠标会“毫无原因地”停止工作,因为他不明白发生了什么

编辑二: 因为我不知道BlazeDS是如何工作的,所以我将使用我自己的示例,您可以尝试翻译它

这是一个简单的调用的样子:

//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));
这就是你要做的:

创建网关以接收呼叫:

[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;
      }
}
如果您有类似的网关,现在可以轻松配置按钮:

<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}"/>


现在,唯一需要确保的是,在“onResult”函数中,即服务器端返回呼叫后将调用的函数,必须确保将amf_busy属性设置为Off(false),并自动启用所有按钮。

我有一个AMFConnector类来进行所有呼叫。每次此类进行调用时,都会将光标设置为忙模式,并将布尔属性设置为true(amf_Busy)。我的所有应用程序都是使用该属性来激活/取消激活按钮来进行调用/命令的。 您的解决方案更快、更简单,但正如您所说的,它会使整个屏幕褪色,对用户不是很友好。现在,当用户看到当他做出一个动作时,按钮就会消失,他会自动意识到他现在必须等待服务器返回一个答案,即使他不理解客户端-服务器调用

编辑: 至于禁用鼠标/键盘,它也不是很友好。如果使用该解决方案,您必须小心使用用户配置文件。用户可能会看到“有时”键盘/鼠标会“毫无原因地”停止工作,因为他不明白发生了什么

编辑二: 因为我不知道BlazeDS是如何工作的,所以我将使用我自己的示例,您可以尝试翻译它

这是一个简单的调用的样子:

//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));
这就是你要做的:

创建网关以接收呼叫:

[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;
      }
}
如果您有类似的网关,现在可以轻松配置按钮:

<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}"/>

现在,您唯一需要确保的是,在“onResult”函数中,即服务器端返回您的呼叫后将调用的函数,您必须确保将amf_busy属性设置为Off(false),并自动启用所有按钮。

对我有效的是

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;
    }
}
尊敬的维耶科,什么对我有用

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;
    }
}

尊敬的维耶科,这里有一个简单的答案:-

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;
    }

下面是一个简单的答案:-

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;
    }

谢谢,这也可以禁用键盘吗?是的,它应该。您可以通过调用Event#preventDefault()和Event#stopPropagation()在捕获阶段禁用键盘事件。
如果(stage)
检查什么(即,在什么条件下是真还是假)?如果FlexGlobals.topLevelApplication未添加到stage,但您要调用该方法,则会得到1009类型错误,因为stage将为null。我在执行
stage.mouseEnabled=false
error\2071:stage类未实现此属性或方法。
根据文档,您是对的
stage.mouseEnabled
也会阻止键盘输入。谢谢,这是否也会以某种方式禁用键盘?是的,它应该。您可以通过调用Event#preventDefault()和Event#stopPropagation()在捕获阶段禁用键盘事件。
如果(stage)
检查什么(即,在什么条件下是真还是假)?如果FlexGlobals.topLevelApplication未添加到stage,但您要调用该方法,则会得到1009类型错误,因为stage将为null。在执行
stage.mouseEnabled=false
error\2071:stage类未实现此属性或方法时,我使用flex 4.6遇到一个错误。
根据文档,你说得对,stage.mouseEnabled也会阻止键盘输入。我还使用BlazeDS进行服务器调用。您能详细描述一下“…将布尔属性设置为true(amf_busy)”吗?代码是什么样子的,它对用户有什么影响?如果鼠标光标处于“忙碌”状态,用户可能不会期望他/她可以单击任何东西,因此在此处禁用鼠标/键盘不会让用户感到困惑。这是真的。虽然我使用网关不仅仅是为了启用/禁用按钮。对我来说,有一个这样的经理是很重要的