Synchronous dialogs in Flex?

How to open a synchronous dialog in Flex? I need to call a function from an external interface (JavaScript) that will open a simple dialog in a Flex application and return a value according to the button that the user clicked (OK / Cancel).

Thus, it must synchronously access the dialog box, i.e. the call waits until the user closes a dialog like this one.

//This function is called by JavaScript
function onApplicationUnload():Boolean
{
  var result:Boolean;
  result = showDialogAndWaitForResult();
  return result
}

Does anyone know how I can do this? I could write a loop that waits until the dialog box sets a flag and then reads the result to return it, but there must be something more elegant and reusable to wait for other asynchronous calls to complete.

EDIT: Unfortunately, the callback does not work, because the JavaScript function calling onApplicationUnload () should return a value (similar to the onApplicationUnload () function in Flex). This JavaScript function has a fixed signature, as it is called by the framework, and I cannot change it. Or in other words: a call from JavaScript to Flex should also be synchronous.

+3
source share
7 answers

You cannot do this in Flex. As David noted, Flex is single-threaded, so you cannot have your own function block while processing a dialog box.

Javascript. , , ( ).

+2

Flex , , "", ..

- :

function onApplicationUnload():void
{
    showDialog(resultMethod);
}

function resultMethod(result:Boolean):void
{
    ExternalInterface.call("javaScriptCallback", [result]);
}
+3

Flex . , . "" .

Cairngorm - :

:

CairngormEventDispatcher.getInstance().addEventListener(ClosingDialogCompleteEvent.DIALOG_COMPLETE, onClosingDialogComplete);

( , .)

:

CairngormEventDispatcher.dispatchEvent(new ClosingDialogCompleteEvent(<parameters>));

:


public function onClosingDialogComplete (e: ClosingDialogCompleteEvent):void
{
   param1 = e.param1;
   param2 = e.param2;
   // etc.
   // Continue processing or set the global variable that signals the main thread to continue.
}

ClosingDialogCompleteEvent. :


package com. ... .event  // You define where the event lives.
{
import com.adobe.cairngorm.control.CairngormEvent;

public class ClosingDialogCompleteEvent extends CairngormEvent
{
    // Event type.
    public static const DIALOG_COMPLETE:String = "dialogComplete";

    public var param1:String;
    public var param2:String;

    public function ClosingDialogCompleteEvent(param1:String, param2:String)
    {
        super(DIALOG_COMPLETE);
        this.param1 = param1;
        this.param2 = param2;
    }
}
}

- Flex. . Flex-only .

+1

... . , : - (

while , , JavaScript. while, . JavaScript . , JavaScript, , XML- Http, blog.

- . JavaScript.

0

flex :

private function deleteFileCheck():void
{
  Alert.show("Are you sure you want to delete this file?",
             "Confirm Delete",
             Alert.YES| Alert.NO,
             this, deleteFileHandler, null, Alert.NO);
}

private function deleteFileHandler(event:CloseEvent):void
{
    if (event.detail == Alert.YES)
    {
        ...do your processing here
    }
}
0

You can fake a synchronous dialog in flex by opening a dialog and then turn off everything in the background. You can see this in action if you are running Alert.show("Hello World");in the application. The background will be grayed out and the user will not be able to click any user interface in the background. The application will "wait" until the user clicks the "OK" button.

-1
source

Source: https://habr.com/ru/post/1698100/


All Articles