seanlail
04-01-2008, 04:20 PM
I'm creating an AIR application in Flex 3 and am having a few issues getting it to start in the bottom right corner of my screen and remember where it's been.
The X and Y coordinates are being reset all the time for some reason and I can't find out where.
This is my main application MXML:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute"
showFlexChrome="false" width="{mainW}" height="{mainH}" alpha="1" applicationComplete="{init()}">
<mx:Script>
<![CDATA[
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Screen;
[Bindable] private var mainW:Number = 200;
[Bindable] private var mainH:Number = 400;
[Bindable] private var mainTitle:String = "Main Window";
private var timer:Timer;
private var s:Screen;
private function init() : void {
nativeWindow.x = -1000;
nativeWindow.y = -1000;
stage.addEventListener( MouseEvent.MOUSE_DOWN, onMouseDown );
timer = new Timer(1000, 1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, alignBottomRight);
timer.start();
}
private function alignBottomRight( e:TimerEvent ) : void {
timer.stop();
s = Screen.mainScreen;
nativeWindow.x = s.visibleBounds.width - nativeWindow.width - 5;
nativeWindow.y = s.visibleBounds.height - nativeWindow.height - 5;
}
private function onMouseDown( e:MouseEvent ) : void {
nativeWindow.startMove();
}
]]>
</mx:Script>
<mx:Panel width="{mainW}" height="{mainH}" title="{mainTitle}" >
<mx:Label text="Text" />
</mx:Panel>
<OtherWindow />
</mx:WindowedApplication>
This is the OtherWindow.MXML:
<?xml version="1.0" encoding="utf-8"?>
<mx:Window xmlns:mx="http://www.adobe.com/2006/mxml" showFlexChrome="false" layout="absolute" >
<mx:Script>
<![CDATA[
[Bindable] private var winX:Number = 30;
[Bindable] private var winY:Number = 100;
[Bindable] private var winW:Number = 140;
[Bindable] private var winH:Number = 200;
[Bindable] private var winTitle:String = "Other Window";
]]>
</mx:Script>
<mx:Panel x="{winX}" y="{winY}" width="{winW}" height="{winH}" title="{winTitle}" />
</mx:Window>
The X and Y coordinates are being reset all the time for some reason and I can't find out where.
This is my main application MXML:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute"
showFlexChrome="false" width="{mainW}" height="{mainH}" alpha="1" applicationComplete="{init()}">
<mx:Script>
<![CDATA[
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Screen;
[Bindable] private var mainW:Number = 200;
[Bindable] private var mainH:Number = 400;
[Bindable] private var mainTitle:String = "Main Window";
private var timer:Timer;
private var s:Screen;
private function init() : void {
nativeWindow.x = -1000;
nativeWindow.y = -1000;
stage.addEventListener( MouseEvent.MOUSE_DOWN, onMouseDown );
timer = new Timer(1000, 1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, alignBottomRight);
timer.start();
}
private function alignBottomRight( e:TimerEvent ) : void {
timer.stop();
s = Screen.mainScreen;
nativeWindow.x = s.visibleBounds.width - nativeWindow.width - 5;
nativeWindow.y = s.visibleBounds.height - nativeWindow.height - 5;
}
private function onMouseDown( e:MouseEvent ) : void {
nativeWindow.startMove();
}
]]>
</mx:Script>
<mx:Panel width="{mainW}" height="{mainH}" title="{mainTitle}" >
<mx:Label text="Text" />
</mx:Panel>
<OtherWindow />
</mx:WindowedApplication>
This is the OtherWindow.MXML:
<?xml version="1.0" encoding="utf-8"?>
<mx:Window xmlns:mx="http://www.adobe.com/2006/mxml" showFlexChrome="false" layout="absolute" >
<mx:Script>
<![CDATA[
[Bindable] private var winX:Number = 30;
[Bindable] private var winY:Number = 100;
[Bindable] private var winW:Number = 140;
[Bindable] private var winH:Number = 200;
[Bindable] private var winTitle:String = "Other Window";
]]>
</mx:Script>
<mx:Panel x="{winX}" y="{winY}" width="{winW}" height="{winH}" title="{winTitle}" />
</mx:Window>