Hi there,
I need to create two separate windows in my AIR Application, and be able to close them both by using a Timer in the main App. or within each window itself ???
Everything should be simple coded just like this test App for mx: which is opening the windows.
Thanks for your effort in making an example, but that is not what is required as per my asking!
I was NOT after a PopUpManager type set up as I do have plentiful of these! I was actually after real separate new Windows to open up from that Application as the PopUpManager type is setting itself on top of each other which I do not need; I need them to be separate so to say OUTSIDE that Application.
This is just creating and opening these two Windows in a very simple manner:
creationComplete="createWindows(event)">
protected function createWindows(evt:FlexEvent):void {
new MyWinOne().open();
new MyWin().open();
}
]]>
</mx:Script>
and be able to close them both by using a Timer in the main App. or within each window itself ???
Where I do not need the timer set up just the closing mechanism for closing these say two Windows withoin the App. or within themselves!
After hours and hours of trying I ONLY can come up with one working solution to get two separate windows and these two windows actually working and doing what I want them to do.
1. Did you test the timer function?
2. How did you create the windows? I created them like this and that works.
<mx:Window id="MyWinOne"/>
<mx:Window id="MyWin"/>
I created the windows as this code bellow - NOTHING else: And the only way it worked for me in the windows etc. itself.
<mx:Script>
<![CDATA[
import mx.core.Window;
import mx.events.FlexEvent;
private function openWindows(evt:Event):void {
new MyWinOne().open();
new MyWinTwo().open();
onStartTimer();
}
]]>
</mx:Script>
I only have problems now that I can;t find a right way that I can close them ??? as in your code above - new MyWinOne().close(); - this does not work at all and I can't find it NOT for the App. nor the windows itself. This is really all the code which has to do with the windows what I REALLY ONLY NEED IS TO CLOSE THESE BUGGERS ??? regards aktell
What kind of code are you using to create the windows? You don't have any var ids and may be that is the problem why you can't close the windows. What are those classes MyWinOne?
The code is as is! And there are no vars as well as they that code does not work with vars! AS IS !!!
I saw the exactly same code today on FLEX Examples exactly the same and maybe at some stage I found it also there long time ago, but I can't remember and there was any code about closing the windows either!
The fact is that it is AS IS and works perfectly well there must be a way to close these windows ! Maybe there is a way that the window itself would be able to close ??? I do not know, but all and everything what goes with it is working ONLY with this code to create the windows in External and Separate windows! regards aktell
Ok, I understand now. Those are custom components (MyWin.mxml). However, you cannot use the syntax you wrote. It would not work. You need to create variables.
PHP Code:
import mx.core.Window; import mx.events.FlexEvent; private var mv:MyWin; private var myTimer:Timer; private var count:int=0;
protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void { mv = new MyWin(); mv.open(); myTimer=new Timer(1000, 6); myTimer.start(); myTimer.addEventListener(TimerEvent.TIMER, popupHandler); }
private function popupHandler(event:TimerEvent):void { if (count == 5) { mv.close(); myTimer.removeEventListener(TimerEvent.TIMER, popupHandler); } count++; }
Thanks a lot for the last piece of code as I seem to have worked out after another day of working on this project what it mite be.
Your code from yesterday worked AS IS perfectly well with my Application set up just as it is needed, BUT it was coded for one window so I extended the code to a second window and here is the problem - Everything stop working! but now going back to the code for one window ONLY - OK again!
I'm really thankful for your help - I really am !!! Most appreciated!
Now if I may ask you if you would have any ideas to get a second window working in this as well because that is what is needed (One is perfect yet only 50% of what I intent to do) I will keep trying as I now know where the problem lies, but would like so much get the second one as well!
I have been able to get both windows working with content !!! but addressing them with two functions instead of one: YET, now the Timers are not working ???
I think I worked it out now! The reason for the problem now within the Timer is this:
I changed the Interval from 5 to 12 to let the windows stay on longer, but ONLY if I change that Interval say to 12 I also have to change the 6 to 13 !!! and everything does work now perfectly.
I really have to admit the (no. 6) I do not understand at all; I worked a lot with Timers, but never came across that one before !!!
Well, my friend 'CancerInform' around 310 private operator in 247 countries will LOVE you for that! great job this was a hard one to crack for me even so I developed it myself, but wanted to do that since over two years thanks a lot again I'm stoked!
Good to hear . You can omit the second argument in the Timer completely and it will go indefinitely. That number determines the number of repeats, so 6 means 6 repeats. As long as you stop the timer and remove the listener it should all be ok.
YES, I understand, but it does all not work if I do that I need to address it with two separate functions in the main module to have it working for the windows ! so I'm happy with that and so I started to extend the Application now, and it works fine just have to see once it is on the Desktop how the memory will behave in respect to the original version of the App. otherwise one big test and one big headache that was!
So thanks again - very happy customer! regards aktell
Advice: Since you have a defined number of repeats, just listen to TimerEvent.TIMER_COMPLETE instead of TimerEvent.TIMER ( no need to define and increment a counter manually and clunk up code with conditions ).
One more thing: Since you need this logic for more than 1 component, ideally you'd implement it outside the actual component. The component shouldn't need to close itself after a defined amount of time and nor should this logic be repeated ( sure, you could make both windows inherit from the same base that implements this closing logic, but from an architectural and performance point of view, it's better if such logic is not implemented into the component itself ).