Home > Flash and Actionscript, Macromedia Flex > Setting position of Alert control in Flex

Setting position of Alert control in Flex

November 2nd, 2007 Leave a comment Go to comments

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: , , ,



  • 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
  • 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.
  • Thanks! I struggled with this, appreciate it!
  • fabio
    Hi!
    I solved the problem with
    myControl=myControlClass(PopUpManager.createPopUp(DisplayObject(Application.application.parentDocument),intervalSelector,true));
    PopUpManager.centerPopUp(myControl);
  • @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
  • 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.
blog comments powered by Disqus