0

我有一个 Flex 应用程序,它在用户单击按钮时向数据库发送查询。由于查询可能很繁重,并且可能需要一分钟,我想显示一个警报,该警报仅在事件从数据库返回后才会关闭(用户将无法自己关闭它)。Flex中可以吗?我怎么做?

我有函数 sendQuery() 和 dataEventHandler()。我想我需要将代码放入 sendQuery() 以显示警报,并在 dataEventHandler() 中放入数据以在数据来自数据库后将其关闭,但是如何使用户“无法关闭”警报?

4

5 回答 5

1

内置的 Flex Alert 类将始终具有某种类型的关闭按钮。

但是,没有理由不能创建自己的组件。然后使用 PopUpManager 打开和关闭它。

于 2012-08-01T15:39:47.240 回答
0

以下代码可能对您有所帮助……(其中一个解决方案……)您可以找到我已经制作了解决方案 1 和解决方案 2……您可以使用其中任何一个,第三种解决方案是创建您自己的自定义组件。请找到下面的代码...。您可以使用以下逻辑来解决您的问题。使用 Timer 检查是否收到数据,或者您可以调度自定义事件并调用 updateAlertPosition 函数。

希望它可以帮助: -

<?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" minWidth="955" minHeight="600"
               >
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.events.CloseEvent;
            import mx.managers.PopUpManager;

            private var minuteTimer:Timer;
            private var alert:Alert;

            private var displayInitialText:String = "Data Not Received, Please wait...."; 
            private var displayDataReveivedText:String = "Data Received...";

            private function timerInit():void
            {
                //Logic to check if data Received.
                minuteTimer = new Timer(3000);
                minuteTimer.addEventListener(TimerEvent.TIMER, updateAlertPosition);
                minuteTimer.start(); 
            }

            private function updateAlertPosition(event:Event = null):void {
                minuteTimer.stop();
                //Solution 1
                //add your flag here if y you want to check if data is received or not
                //if(Data Received)
                alert.mx_internal::alertForm.mx_internal::buttons[0].enabled = true;
                alert.mx_internal::alertForm.mx_internal::buttons[1].enabled = true;
                alert.mx_internal::alertForm.mx_internal::textField.text = displayDataReveivedText;
                //Solution 2
                //alert.enabled = true;
                //If you want to remove it automatically
                //closeAutomatically();
            }

            private function closeAutomatically():void
            {
                PopUpManager.removePopUp(alert);
            }

            private function clickHandler():void
            {
                //Start Timer
                timerInit();
                //Solution 1
                alert = Alert.show(displayInitialText, "Alert", Alert.OK|Alert.CANCEL,this,alertCloseHandler);
                alert.mx_internal::alertForm.mx_internal::buttons[0].enabled = false;
                alert.mx_internal::alertForm.mx_internal::buttons[1].enabled = false;
                //Solution 2
                //alert.enabled = false;
            }

            private function alertCloseHandler(event:CloseEvent):void
            {
                if(event.detail == Alert.CANCEL)
                {
                    //Some Code on close
                }
                else
                {
                    //Some Code on OK
                }

            }
        ]]>
    </fx:Script>

    <s:Button label="Show Alert" x="100" y="100" click="clickHandler()"/>
</s:Application>
于 2012-08-02T05:16:37.967 回答
0

作为一个想法,您可以创建一个自定义警报然后:

  1. 显示警报
  2. 禁用应用程序。
  3. 隐藏警报。
  4. 启用应用程序。

警报示例:

<?xml version="1.0" encoding="utf-8"?>
<s:Group 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="400" height="300"
         creationComplete="onCreationComplete(event)">

    <s:Rect>
        <s:fill>
            <s:SolidColor color="0xFFFFFF"/>
        </s:fill>
        <s:stroke>
            <s:SolidColorStroke />
        </s:stroke>
    </s:Rect>

    <s:Label text="Please Wait..."/>

    <fx:Script>
        <![CDATA[
            import mx.core.FlexGlobals;
            import mx.events.FlexEvent;
            import mx.managers.PopUpManager;
            public static function show():void
            {
                PopUpManager.createPopUp(FlexGlobals.topLevelApplication);      
            }

            public static function hide():void
            {
                PopUpManager.removePopUp(this);
                FlexGlobals.topLevelApplication.enabled = true;
            }

            protected function onCreationComplete(event:FlexEvent):void
            {
                PopUpManager.centerPopUp(this);
                FlexGlobals.topLevelApplication.enabled = false;
            }
        ]]>
    </fx:Script>
</s:Group>

用法:

YourAlert.show();

YourAlert.hide();
于 2012-08-02T11:12:40.513 回答
0

@Alex,我使用了您的代码,但对其进行了一些修改,因为出现了一些错误:

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx"
         creationComplete="creationCompleteHandler()" width="100%" height="100%">
    <fx:Script>
        <![CDATA[

            import mx.core.FlexGlobals;
            import mx.core.UIComponent;
            import mx.managers.PopUpManager;

            ///////////////////////////////////////
            //// public functions - my group is ImageViewer.mxml component


            public static function show():ImageViewer {
                return PopUpManager.createPopUp(FlexGlobals.topLevelApplication as DisplayObject, ImageViewer) as ImageViewer;
            }

            public function hide():void {
                PopUpManager.removePopUp(this);
                FlexGlobals.topLevelApplication.enabled = true;
            }


            ////////////////////////////
            //// component events

            private function creationCompleteHandler():void {
                PopUpManager.centerPopUp(this);
                FlexGlobals.topLevelApplication.enabled = false;
            }
            ]]>
    </fx:Script>
</s:Group>

并称它为:

var imageviewer:ImageViewer = ImageViewer.show();
//imageviewer.imageURL = _value_dto.value;
于 2013-03-04T12:17:36.687 回答
0

制作一个覆盖整个应用程序的 0-0.2 alpha 形状(可能您会想要监听 resizeevents),并在其中添加一个自定义面板,其中包含消息。

于 2012-08-02T10:34:03.807 回答