Setting position of Alert control in Flex

It seems, there is no direct way of setting position (x, y) of Alert control in Flex 2. The trivial method (setting x, y) is either buggy or there must be some official way, which I am not aware of.

I found some different ways to do that:-

var alert:Alert = Alert.show("Can you see me on random positions?",
"I am an Alert box", Alert.YES | Alert.NO,
this, alertClickHandler, null, Alert.NO);
PopUpManager.centerPopUp (alert);
var newX:Number = 200;
var newY:Number = 200;
alert.move (newX, newY)

var alert:Alert = Alert.show("Can you see me on random positions?",
"I am an Alert box", Alert.YES | Alert.NO,
this, alertClickHandler, null, Alert.NO);
var newX:Number = 200;
var newY:Number = 200;
callLater (alert.move, [newX, newY]);

Following, to me, sounds like a little expensive because we are asking for the immediate validation.

var alert:Alert = Alert.show("Can you see me on random positions?",
"I am an Alert box", Alert.YES | Alert.NO,
this, alertClickHandler, null, Alert.NO);
var newX:Number = 200;
var newY:Number = 200;
alert.validateNow ();
alert.move (newX, newY);

Technorati tags: , , ,

  • John

    Hello,
    Cool stuff…
    The centerPopUp method centers the popup relative to it’s parent so another way to place it at certain position is by setting a specific parent component.

  • @John: Right, that’s a workaround to invoke validate the Alert before setting the properties. All of the above methods invalidate and set the property and invalidate…
    I am still trying to figure out the reason, I am looking into the code to find the issue with it…
    -abdul

  • fabio

    Hi!
    I solved the problem with
    myControl=myControlClass(PopUpManager.createPopUp(DisplayObject(Application.application.parentDocument),intervalSelector,true));
    PopUpManager.centerPopUp(myControl);

  • Thanks! I struggled with this, appreciate it!

  • Name

    Excellent.. i went all over the internet but could not find a solution… your method works great!

    • Thanks for feedback, glad you found it useful.

  • Arnold Aprieto

    Thanks Abdul. This has been very useful.
    It’s just weird to why alert.x and alert.y. did not work, suffice to say they are part of the attributes for Alert.

    • Alex

      You can use Alert.show(“text”, “title”, Alert.OK, Application.application as Application, handler); to automatically center the Alert on your entire application initially (Application.application as Application is the Object it will center on in this case).

      You have to coerce it to type Application because the static var Application.application is of type Object

  • Thank you very much!! I put all my controls in a canvas, then the alert didn’t show in the center. Then I found your tips. You saved me a lot of times. Thanks again!