2012-08-01 84 views
0

我有一個Flex應用程序,當用戶單擊按鈕時,該應用程序向數據庫發送查詢。由於查詢可能很重,並且可能需要一分鐘,所以我想顯示一個警報,只有在事件從數據庫中返回後纔會關閉(用戶將無法自行關閉它)。在Flex中可能嗎?我怎麼做?顯示用戶不能關閉的提醒,在事件中自動關閉

我有函數sendQuery()和dataEventHandler()。我想我需要將代碼放入sendQuery()中以顯示警報,並在dataEventHandler()將數據從數據庫中提取出來後關閉它,但是如何讓用戶的警報「不可關閉」?

回答

1

內置的Flex Alert類將始終具有某種類型的關閉按鈕。

但是,沒有理由不能創建自己的組件;然後使用PopUpManager打開並關閉它。

+0

我第二。創建您自己的彈出式控件。你甚至可以添加一個不確定的進度條,以獲得一個漂亮的動畫。使用PopupManager顯示/解除你的控制。 – 2012-08-02 11:13:50

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> 
0

做出0-0.2阿爾法形狀什麼涵蓋整個應用程序(可能你會想監聽resizeevents),和一個自定義面板添加到中間它,與消息。

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(); 
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;