3

I need to close the windows2 to open windows3. I have the next code: I'm a begginer on titanium , please help me.

    //Windows1.XML
    <Alloy>
        <Window exitOnClose="false">
            <Button   onClick="openWindows2" visible="false">
            </Button>
        </Window>
    </Alloy>
    CONTROLLER
    //Window1.js
    function openWindows2(e)
    {
      var Window2=Alloy.createController('Window2').getView();
      newWindows.open(); 
    }
    $.Windows1.open()

This code is the second view i open with the first controller on windows1 //Window2.XML

    <Alloy>
        <Window exitOnClose="false">
            <Button   onClick="openWindows3" visible="false">
            </Button>
        </Window>
    </Alloy>

the controller function open the windows 3 //Window2.js

    function openWindows3(e)
    {
      var Window3=Alloy.createController('Window3').getView();
      newWindows.open(); 
    }
    $.Windows2.open()

my windows 3 //Window3.XML

    <Alloy>
        <Window exitOnClose="false">
            <Button  onClick="anotherFn" visible="false">
            </Button>
        </Window>
    </Alloy>
    //Window3.js
    $.Windows3.open()
Origineil
  • 3,108
  • 2
  • 12
  • 17
aquinoaldair
  • 39
  • 1
  • 2
  • 6

3 Answers3

6

You define your window in XML, say mycoolwindow.xml.

Then from some other part of your code:

 var win=Alloy.createController('mycoolwindow').getView();
 win.open();

See example here: https://github.com/ricardoalcocer/AlloyOpenWindow

or go to this link: http://www.youtube.com/watch?v=CB26lUj0UBQ

Martin Turjak
  • 20,896
  • 5
  • 56
  • 76
Amol Navsupe
  • 172
  • 1
  • 11
1

Place this function in Window2.js:

function openWindow3(){
Alloy.createController('Window3');
$.Window2.close();
}

window3.js:

$.Window3.open();
0

First if all closing a window and opening a new window simultaneously doesn't works in Android. The app crashes. Rather what I would suggest is remove all childrens of the window and hide it (For Android Only), for IOS you can close it. This way the memory leaks would also be managed.

About open a window avoid initializing new objects as they occupies memory. Directly use the open function . For eg :

Alloy.createController('mycoolwindow').getView().open();
Ashish
  • 1,978
  • 1
  • 15
  • 7