If you look in the framework code of Alert(), you'll see that it appears
to force itself to center (shown at the bottom ). You could probably
subclass the Alert class and override this behavior. It seems like kind
of a janky solution ...
Actually, you may be able to have the Alert() center by passing in a
"parent" parameter to the show() method, and it should center in that
area. So, if you had a "header" displayObject, and you wanted it to
center to that object, you could do the following:
Alert.show( "My message", Alert.OK, header );
Code from Alert.as
-------------------
override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
// Position the AlertForm inside the "client area" of the Panel
var vm:EdgeMetrics = viewMetrics;
alertForm.setActualSize(unscaledWidth - vm.left - vm.right -
getStyle("paddingLeft") -
getStyle("paddingRight"),
unscaledHeight - vm.top - vm.bottom -
getStyle("paddingTop") -
getStyle("paddingBottom"));
// Choose an (x,y) position that centers me in my parent.
if (!init)
{
var x:Number;
var y:Number;
if (parent == systemManager)
{
x = (screen.width - measuredWidth) / 2;
y = (screen.height - measuredHeight) / 2;
}
else
{
x = (parent.width - measuredWidth) / 2;
y = (parent.height - measuredHeight) / 2;
}
// Set my position, because my parent won't do it for me.
move(Math.round(x), Math.round(y));
init = true;
}
P Smith wrote:
>
> Can the position of an Alert window be controlled? Rather than
> centered, I would like my Alert box to be positioned 20 pixels from
> the top of the stage.
>
> When I have created an Alert instance, I have been unable to get
> move() or setting x and y to control the position of the Alert window.
>
> I see that the position of a TitleWindow can be controlled. LiveDocs
> for TitleWindow has an example using localToGlobal() at the bottom of
> this page:
> http://livedocs.macromedia.com/flex/2/langref/mx/containers/TitleWindow.html
> <http://livedocs.macromedia.com/flex/2/langref/mx/containers/TitleWindow.html>
>
> When modifying that TitleWindow example to use an Alert instead, the
> same code fails to control the position of the Alert window (where it
> did control the TitleWindow). Following below is the TitleWindow
> example modified to use an Alert.
>
> I appreciate assistance understanding this.
>
> Pete
>
> ** TitleWindow example modified to use an Alert **
>
> <?xml version="1.0" encoding="utf-8"?>
> <!-- Main application to demonstrate TitleWindow layout container. -->
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
>
> <mx:Script>
> <![CDATA[
>
> import mx.controls.Alert;
> //import mx.managers.PopUpManager;
> //import mx.containers.TitleWindow;
> import flash.geom.Point;
>
> private var point1:Point = new Point();
>
> // Open the TitleWindow container.
> // Cast the return value of the createPopUp() method
> // to SimpleTitleWindowExample, the name of the
> // component containing the TitleWindow container.
> private function showWindow():void {
> var login:Alert;
> //var
> login:SimpleTitleWindowExample=SimpleTitleWindowExample(PopUpManager.createPopUp(
>
> this, SimpleTitleWindowExample , true));
>
> // Calculate position of TitleWindow in Application's
> coordinates.
> point1.x=myButton.x;
> point1.y=myButton.y;
> point1=myButton.localToGlobal(point1);
>
> login = Alert.show('Hello World!', 'Message');
>
> login.x=point1.x+25;
> login.y=point1.y+25;
>
> // Pass a reference to the TextInput control
> // to the TitleWindow container so that the
> // TitleWindow container can return data to the main
> application.
> //login.loginName=returnedName;
> }
> ]]>
> </mx:Script>
>
> <mx:Panel title="TitleWindow Container Example" height="75%"
> width="75%"
> paddingTop="10" paddingLeft="10" paddingRight="10"
> paddingBottom="10">
>
> <mx:Button id="myButton" label="Click to open the TitleWindow
> container"
> click="showWindow();"/>
>
> <mx:Text id="returnedName" text="" width="100%"/>
>
> </mx:Panel>
> </mx:Application>
>
> ------------------------------------------------------------------------
> Stay in the know. Pulse on the new Yahoo.com. Check it out.
> <http://us.rd.yahoo.com/evt=42974/*http://www.yahoo.com/preview>
>
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/flexcoders/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/