How to get children of the current window?

You must Login before you can answer or comment on any questions.

Hi, i'm using Titanium 2.1.0, Android 4.1, Windows 7, I created a window in the app.js and I created an other file where i get the current window var window = Ti.UI.currentWindow; when i tried to get the children with window.getChildren() it returned an empty array whereas i added some views and when i tried to use this var w =Ti.UI.getCurrentWindow() i got an error Object has no method getCurrentWindow Thanks fou your attention.

1 Answer

Accepted Answer

Have you tried just using win.children??

— answered 8 months ago by Anthony Decena
answer permalink
6 Comments
  • I just tried it but i got the same result an empty array

    — commented 8 months ago by james priso

  • Maybe you need to post some more complete code. I just ran this and it seemed to work as expected:

    var win = Ti.UI.createWindow({
        backgroundColor:'#fff'
    });
     
    var view = Ti.UI.createView({
        backgroundColor:'red',
        width:100,
        height:100
    });
    win.add(view);
     
    var c = win.children;
    Ti.API.info(c);
     
    win.open();

    — commented 8 months ago by Anthony Decena

  • in app.js

    var main_window = Ti.UI.createWindow({  
        url:'windows/connexion.js',  
        backgroundColor: '#e7e7e7',
        height:Ti.Platform.displayCaps.platformHeight,  
        width:Ti.Platform.displayCaps.platformWidth,
        stock_f_c : 'null',
        stock_f_c_1 : 'null',
        fullscreen:true,  
        navBarHidden:true
    });  
    main_window.open();
    in connexion.js
    var win = Titanium.UI.currentWindow;
    var width_bouton = 200*Ti.Platform.displayCaps.platformWidth/320;
     var height_bouton = 50*Ti.Platform.displayCaps.platformHeight/480;
    var height_body = Ti.Platform.displayCaps.platformHeight-Ti.Platform.displayCaps.platformHeight/7; 
          body = Ti.UI.createView({
                                  width : Ti.Platform.displayCaps.platformWidth,
                                 height : height_body ,
                                 getElementByNom : getElementByNom,
                                // borderWidth : 1,
                                // borderColor : 'green',
                                 top :  Ti.Platform.displayCaps.platformHeight/7
                                 });                      
    win.add(body);
    Ti.API.info(win.children.length);
    that's it.

    — commented 8 months ago by james priso

  • Show 3 more comments

Your Answer

Think you can help? Login to answer this question!