stevemcl
stevemcl

Reputation: 387

How do you place the Flex Alert box in a certain x,y position?

How do you place the Flex Alert box in a certain x,y position, the following code does not work, the Alert box is always centered in the screen.

<?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" >

    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            protected function showAlert(event:MouseEvent):void
            {

                myAlert = Alert.show('alert', 'Error - ');

                myAlert.x = 40; 
                myAlert.y = 50;
//              myAlert.move(-400,-500);  // doesn't work either
            }
            private var myAlert:Alert;
        ]]>
    </fx:Script>
    <s:Button label="click me" click="showAlert(event)" />
</s:Application>

Upvotes: 3

Views: 1310

Answers (1)

Joel Harmon
Joel Harmon

Reputation: 227

Calling the centerPopUp function of the PopUpManager before setting the x & y co-ordinates will allow you to change the position of the Alert window. I've updated the script that you provided so that it does position the Alert window appropriately:

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

        private var myAlert:Alert;

        protected function showAlert(event:MouseEvent):void
        {
            myAlert = Alert.show('alert', 'Error - ');
            PopUpManager.centerPopUp(myAlert);
            myAlert.x = 40; 
            myAlert.y = 50;
        }

    ]]>
</fx:Script>

Upvotes: 7

Related Questions