Creating two separate Windows ....
A Flash Developer Resource Site

Results 1 to 18 of 18

Thread: Creating two separate Windows ....

  1. #1
    Senior Member
    Join Date
    Apr 2008
    Location
    Rotorua / New Zealand
    Posts
    110

    Creating two separate Windows ....

    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.

    creationComplete="createWindows(event)">

    <mx:Script>
    <![CDATA[

    import mx.core.Window;
    import mx.events.FlexEvent;

    protected function createWindows(evt:FlexEvent):void {

    new MyWinOne().open();
    new MyWin().open();
    }
    ]]>
    </mx:Script>

    Any ideas/help would be appreciated ! regards aktell

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,436
    Here I made an example:
    PHP Code:
    <fx:Script>
        <![
    CDATA[
            
    import mx.events.FlexEvent;
            
    import mx.managers.PopUpManager;
            
            
    import spark.components.TitleWindow;
            private var 
    tw1:TitleWindow;
            private var 
    tw2:TitleWindow;
            private var 
    count:int=0;
            
            
            protected function 
    application1_creationCompleteHandler(event:FlexEvent):void
            
    {
                
    tw1 = new TitleWindow();
                
    tw1.width 200;
                
    tw1.height 200;
                
    tw1.title "Popup One";
                
    tw2 = new TitleWindow();
                
    tw2.width 200;
                
    tw2.height 200;
                
    tw2.title "Popup Two";
                
    PopUpManager.addPopUp(tw1thistrue);
                
    PopUpManager.centerPopUp(tw1);
                
                
    PopUpManager.addPopUp(tw2thistrue);
                
    PopUpManager.centerPopUp(tw2);
                
                
                var 
    myTimer:Timer = new Timer(1000,10);
                
    myTimer.start();
                
    myTimer.addEventListener(TimerEvent.TIMER,popupHandler);
            }
            private function 
    popupHandler(event:TimerEvent):void
            
    {
                if(
    count==3)
                {
                    
    PopUpManager.removePopUp(tw2);
                }
                if(
    count==6)
                {
                    
    PopUpManager.removePopUp(tw1);
                }
                
    count++;
            }
            
        ]]>
      </
    fx:Script
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    Senior Member
    Join Date
    Apr 2008
    Location
    Rotorua / New Zealand
    Posts
    110
    Hi there,

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

    <mx:Script>
    <![CDATA[

    import mx.core.Window;
    import mx.events.FlexEvent;

    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!

    regards aktell
    Last edited by aktell; 12-10-2012 at 06:40 PM.

  4. #4
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,436
    May be this is what you are looking for?
    PHP Code:
    <fx:Script>
            <![
    CDATA[
                
    import mx.core.Window;
                
    import mx.events.FlexEvent;

                private var 
    myTimer:Timer;
                private var 
    count:int=0;

                protected function 
    application1_creationCompleteHandler(event:FlexEvent):void
                
    {
                    
    MyWinOne.open();
                    
    MyWin.open();
                    
    myTimer=new Timer(10006);
                    
    myTimer.start();
                    
    myTimer.addEventListener(TimerEvent.TIMERpopupHandler);
                }

                private function 
    popupHandler(event:TimerEvent):void
                
    {
                    if (
    count == 3)
                    {
                        
    MyWinOne.close();
                    }
                    if (
    count == 5)
                    {
                        
    MyWin.close();
                        
    myTimer.removeEventListener(TimerEvent.TIMERpopupHandler);
                    }
                    
    count++;
                }
            ]]>
        </
    fx:Script
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  5. #5
    Senior Member
    Join Date
    Apr 2008
    Location
    Rotorua / New Zealand
    Posts
    110
    Thanks again I will give that a try later and let you know! Thanks again regards aktell

  6. #6
    Senior Member
    Join Date
    Apr 2008
    Location
    Rotorua / New Zealand
    Posts
    110
    Hi again,

    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.

    This is the code:

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


    Now I have still recurring the same problem HOW TO CLOSE THESE TWO windows in the main App or from each within itself !!!

    I know this code is wrong BUT the ONLY version without Error messages, but still NOT working using timer code as previously supplied!

    <mx:Script>
    <![CDATA[

    private var myTimer:Timer;
    private var count:int = 0;
    private function onStartTimer():void {

    myTimer = new Timer(1000, 6);
    myTimer.start();

    myTimer.addEventListener(TimerEvent.TIMER, popupHandler);

    }
    private function popupHandler(event:TimerEvent):void {

    if (count == 5) {

    new MyWinOne().close();
    }
    if (count == 7) {

    new MyWinTwo().close();

    myTimer.removeEventListener(TimerEvent.TIMER, popupHandler);
    }
    count++;
    }
    ]]>
    </mx:Script>

  7. #7
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,436
    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 don't know your other code, so I can't say.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  8. #8
    Senior Member
    Join Date
    Apr 2008
    Location
    Rotorua / New Zealand
    Posts
    110
    Hi again,

    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

  9. #9
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,436
    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 right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  10. #10
    Senior Member
    Join Date
    Apr 2008
    Location
    Rotorua / New Zealand
    Posts
    110
    Hi again,

    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

  11. #11
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,436
    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(10006);
                    
    myTimer.start();
                    
    myTimer.addEventListener(TimerEvent.TIMERpopupHandler);
                }
                
                private function 
    popupHandler(event:TimerEvent):void
                
    {
                    if (
    count == 5)
                    {
                        
    mv.close();
                        
    myTimer.removeEventListener(TimerEvent.TIMERpopupHandler);
                    }
                    
    count++;
                } 
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  12. #12
    Senior Member
    Join Date
    Apr 2008
    Location
    Rotorua / New Zealand
    Posts
    110
    Hi again,

    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!

    regards aktell

  13. #13
    Senior Member
    Join Date
    Apr 2008
    Location
    Rotorua / New Zealand
    Posts
    110
    Hi there again,

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

    <mx:Script>
    <![CDATA[

    import mx.core.Window;
    import mx.events.FlexEvent;

    private var ma:MyWinOne;

    private var myTimerOne:Timer;
    private var countOne:int=0;

    protected function app_creationCompleteHandlerOne(event:FlexEvent):vo id {

    ma = new MyWinOne();
    ma.open();

    myTimerOne=new Timer(1000, 6);
    myTimerOne.start();
    myTimerOne.addEventListener(TimerEvent.TIMER, popupHandlerOne);
    }

    private function popupHandlerOne(event:TimerEvent):void {

    if (countOne == 12) {

    ma.close();
    myTimerOne.removeEventListener(TimerEvent.TIMER, popupHandlerOne);
    }
    countOne++;
    }
    ]]>
    </mx:Script>

  14. #14
    Senior Member
    Join Date
    Apr 2008
    Location
    Rotorua / New Zealand
    Posts
    110
    Hi there again,

    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!

    <mx:Script>
    <![CDATA[

    import mx.core.Window;
    import mx.events.FlexEvent;

    private var ma:MyWinOne;

    private var myTimerOne:Timer;
    private var countOne:int=0;

    protected function app_creationCompleteHandlerOne(event:FlexEvent):vo id {

    ma = new MyWinOne();
    ma.open();

    myTimerOne=new Timer(1000, 6);
    myTimerOne.start();
    myTimerOne.addEventListener(TimerEvent.TIMER, popupHandlerOne);
    }

    private function popupHandlerOne(event:TimerEvent):void {

    if (countOne == 12) {

    ma.close();
    myTimerOne.removeEventListener(TimerEvent.TIMER, popupHandlerOne);
    }
    countOne++;
    }
    ]]>
    </mx:Script>

  15. #15
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,436
    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.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  16. #16
    Senior Member
    Join Date
    Apr 2008
    Location
    Rotorua / New Zealand
    Posts
    110
    Hi there,

    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

  17. #17
    Junior Member
    Join Date
    Nov 2012
    Posts
    4
    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 ).

  18. #18
    Junior Member
    Join Date
    Nov 2012
    Posts
    4
    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 ).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com