将 Flex 应用程序重新连接到后端时模糊并禁用背景
我的 Flex 4.5 应用程序有许多来自俄罗斯和乌克兰的用户,他们的互联网连接很差,Socket 连接经常中断,必须重新连接。
目前,我在 IOErrorEvent.IO_ERROR 和 Event.CLOSE 事件上将 currentState 设置为“offline”,并仅显示该状态下的 1 个组件:
<mx:ProgressBar indeterminate="true"
horizontalCenter="0" verticalCenter="0"
label="Reconnecting..." labelPlacement="center"
includeIn="offline" />
但这不是最好的方法 - 因为用户会突然看到白屏和进度条,而背景消失。
(实际上它不是一个应用程序,而是一个纸牌游戏 - 因此用户至少可以在重新连接时研究他们的纸牌)。
所以我想知道,是否有一种方法可以在 Flex 中模糊和禁用背景 - 类似于 mx.controls.Alert,但没有“确定”按钮,并且在 Socket 连接恢复时可关闭?
更新:
我按照 Chris 的建议使用了 PopUpManager,但由于某种原因不确定的 ProgressBar 没有动画。我怎样才能“启动”它?
MyApp.mxml:
<?xml version="1.0" encoding="utf-8"?>
<s:Application
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="700" height="525"
backgroundColor="#CCFFCC"
initialize="systemManager.stage.scaleMode=StageScaleMode.SHOW_ALL"
applicationComplete="init()">
<fx:Script>
<![CDATA[
import mx.managers.PopUpManager;
import mx.controls.ProgressBar;
private function init():void {
var bar:Connecting = PopUpManager.createPopUp(this, Connecting, true) as Connecting;
PopUpManager.centerPopUp(bar);
}
private function fullScreen(event:MouseEvent):void {
stage.displayState =
stage.displayState == StageDisplayState.NORMAL ?
StageDisplayState.FULL_SCREEN :
StageDisplayState.NORMAL;
}
]]>
</fx:Script>
<s:states>
<s:State name="normal" />
<s:State name="connected" />
</s:states>
<s:CheckBox right="10" bottom="10"
label="Full screen"
click="fullScreen(event)" />
</s:Application>
Loading.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:ProgressBar
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
indeterminate="true" fontWeight="normal"
label="Connecting..." labelPlacement="center">
</mx:ProgressBar>
更新2:
通过在组中嵌入ProgressBar解决了这个问题
My Flex 4.5 application has many users from Russia and Ukraine with poor internet connections and Socket connections often interrupt and have to be reconnected.
Currently I set currentState to "offline" on IOErrorEvent.IO_ERROR and Event.CLOSE events and display just 1 component in that state:
<mx:ProgressBar indeterminate="true"
horizontalCenter="0" verticalCenter="0"
label="Reconnecting..." labelPlacement="center"
includeIn="offline" />
but this is not the best way - because the users are suddenly presented by the white screen and the progress bar, while the background disappears.
(Actually it is not an application, but a card game - so the users could at least study their cards while being reconnected).
So I wonder, if there is a way to blur and disable background in Flex - similar to mx.controls.Alert, but without an OK-button and being dismissable when the Socket connection is restored?
UPDATE:
I've used a PopUpManager as suggested by Chris, but the indeterminate ProgressBar is not animated for some reason. How can I "kick start" it?
MyApp.mxml:
<?xml version="1.0" encoding="utf-8"?>
<s:Application
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="700" height="525"
backgroundColor="#CCFFCC"
initialize="systemManager.stage.scaleMode=StageScaleMode.SHOW_ALL"
applicationComplete="init()">
<fx:Script>
<![CDATA[
import mx.managers.PopUpManager;
import mx.controls.ProgressBar;
private function init():void {
var bar:Connecting = PopUpManager.createPopUp(this, Connecting, true) as Connecting;
PopUpManager.centerPopUp(bar);
}
private function fullScreen(event:MouseEvent):void {
stage.displayState =
stage.displayState == StageDisplayState.NORMAL ?
StageDisplayState.FULL_SCREEN :
StageDisplayState.NORMAL;
}
]]>
</fx:Script>
<s:states>
<s:State name="normal" />
<s:State name="connected" />
</s:states>
<s:CheckBox right="10" bottom="10"
label="Full screen"
click="fullScreen(event)" />
</s:Application>
Loading.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:ProgressBar
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
indeterminate="true" fontWeight="normal"
label="Connecting..." labelPlacement="center">
</mx:ProgressBar>
UPDATE 2:
Solved that by embedding ProgressBar in a Group
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当连接丢失时,将应用程序(或要模糊的顶级组件)的
enabled
属性设置为false
并返回到true
> 当重新建立连接时。“Application”定义了一个皮肤状态
disabled
,当组件的“enabled”属性设置为“false”时,该状态会自动变为 currentState。这意味着您可以创建如下所示的皮肤:这将仅在“禁用”状态下包含“BlurFilter”。将“enabled”属性设置为“false”将自动阻止所有用户与该组件的交互。
When the connection is lost, set the
enabled
property of your Application (or the top level component you want to blur) tofalse
and back totrue
when the connection is reestablished.'Application' defines a skin state
disabled
which automatically becomes the currentState when the components 'enabled' property is set to 'false'. This means you can create a skin like this:This will include the 'BlurFilter' only in the 'disabled' state. And setting the 'enabled' property to 'false' will automatically block all user interaction with the component.
当您使用警报时,真正发生的是一个弹出组件显示在您的应用程序顶部。您可以使用 PopUpManager 模糊背景,同时向用户显示一条小消息(可能是使用 Canvas 的自定义组件)。
When you are using Alert what is really happening is that a popup component is displayed on top of your app. You can achieve the same effect using the PopUpManager to blur the background while displaying a small message to the user(maybe a custom component using Canvas).