"Looping" between windows?

Discussion in 'Jiggy Runtime Development' started by jpat53, Jun 21, 2008.

  1. jpat53

    jpat53 New Member

    Joined:
    May 19, 2008
    Messages:
    112
    Likes Received:
    0
    I have just been playing around with Jiggy, and i want to have a main menu with a NavBar that has a button (window 1) that will link to a second window, and on the second window ( window 2) a NavBar that has a button that links back to the first window.

    The problem is that I have only been able to go from window 1 to window 2 and then back to window 1 one time and then the window 1 button is disabled, but i want to have infinite switches between the two.

    So I essentially want to "loop" between them, but it only allows one switch.

    Does anyone have any suggestions or codes?
  2. Ryan

    Ryan Well-Known Member

    Joined:
    Jan 19, 2008
    Messages:
    4,129
    Likes Received:
    28
    Device:
    Nexus 4
    use this.

    name the first page first.js
    name the second page second.js


    then use this code on first.js

    var titleBar = new UINavigationBar( [ 0 , 0 , 320 , 48 ] );
    titleBar.setBarStyle(1);
    var title = new UINavigationItem( "Page 1" );
    titleBar.pushNavigationItem( title );
    titleBar. showButtonsWithLeftTitle(null,"Page 2");
    dirView.addSubview( titleBar );
    titleBar.onButtonClicked = function ( titleBar, button )
    {
    if(button == 0)
    {
    include("second.js");
    }
    }


    and this for second.js

    var titleBar = new UINavigationBar( [ 0 , 0 , 320 , 48 ] );
    titleBar.setBarStyle(1);
    var title = new UINavigationItem( "Page 2" );
    titleBar.pushNavigationItem( title );
    titleBar. showButtonsWithLeftTitle("Page 1",null);
    dirView.addSubview( titleBar );
    titleBar.onButtonClicked = function ( titleBar, button )
    {
    if(button == 1)
    {
    include("first.js");
    }
    }



    this should work, theoretically .
  3. jpat53

    jpat53 New Member

    Joined:
    May 19, 2008
    Messages:
    112
    Likes Received:
    0
    Okay, well that helps alot so thank you.

    The only question i have is is there some thing that needs to be put in at the if(button == 0) line below? because when i try to touch the button on page 1 it gives me an error that the button in that line of my code has not been defined.
    {
    if(button == 0)
    {
    include("second.js");
    }
    }
    Thanks again for the help
  4. Ryan

    Ryan Well-Known Member

    Joined:
    Jan 19, 2008
    Messages:
    4,129
    Likes Received:
    28
    Device:
    Nexus 4
    oh try changing the 0 to 1?
  5. jpat53

    jpat53 New Member

    Joined:
    May 19, 2008
    Messages:
    112
    Likes Received:
    0
    That doesn't seem to work. I will post what my code is so far, maybe you could point out what is wrong?

    // com.app.johnstestapp
    // /Applications/John's Test App.app/main.js

    Plugins.load( "UIKit" );

    ( "first.js" );
    var window = new UIWindow( UIHardware.fullScreenApplicationContentRect );
    window.setHidden( false );
    window.orderFront();
    window.makeKey();
    window.backgroundColor = [ 0 , 1 , 0 , 1 ];

    var mainView = new UIView();
    window.setContentView( mainView );

    var textbox1 = new UITextField( [ 20 , 50 , 45, 480 ] );

    var bar = new UINavigationBar( [ 0 , 0 , 320 , 50 ] );
    bar.showButtonsWithLeftTitle( null , "Start" , false );

    mainView.addSubview( bar );

    var itemOne = new UINavigationItem( "Test" );
    bar.pushNavigationItem( itemOne );

    bar.onButtonClicked =
    function( theBar , theButton )
    {
    if(button == 1)
    {
    include("second.js");
    }
    }

    ( "second.js" );
    var window = new UIWindow( UIHardware.fullScreenApplicationContentRect );
    window.setHidden( false );
    window.orderFront();
    window.makeKey();
    window.backgroundColor = [ 1 , 1 , 1 , 1 ];

    var mainView = new UIView();
    window.setContentView( mainView );

    var bar = new UINavigationBar( [ 0 , 0 , 320 , 50 ] );
    bar.showButtonsWithLeftTitle( null , "Back" , false );;
    mainView.addSubview( bar );

    var itemOne = new UINavigationItem( "App Name" );
    bar.pushNavigationItem( itemOne );

    bar.onButtonClicked =
    function( theBar , theButton )
    {
    if(button == 1)
    {
    include("first.js");
    }
    }
  6. Ryan

    Ryan Well-Known Member

    Joined:
    Jan 19, 2008
    Messages:
    4,129
    Likes Received:
    28
    Device:
    Nexus 4
    you have two ;; on this line


    bar.showButtonsWithLeftTitle( null , "Back" , false );;
  7. jpat53

    jpat53 New Member

    Joined:
    May 19, 2008
    Messages:
    112
    Likes Received:
    0
    Thanks for the help, but i think since this is my first time with Javascript I am just going to start over, as I think that i have messed up my code as it is.

    But thanks for all of your help if i knew how to +rep i would but i don't.
  8. Ryan

    Ryan Well-Known Member

    Joined:
    Jan 19, 2008
    Messages:
    4,129
    Likes Received:
    28
    Device:
    Nexus 4
    they took away the rep system lol...

    gimme 5 minutes and ill post you a working script.
  9. jpat53

    jpat53 New Member

    Joined:
    May 19, 2008
    Messages:
    112
    Likes Received:
    0
    Haha well that shows how much I know.
  10. Ryan

    Ryan Well-Known Member

    Joined:
    Jan 19, 2008
    Messages:
    4,129
    Likes Received:
    28
    Device:
    Nexus 4
    Ok, make 2 files.

    Main.js and Second.js


    In Main.js copy and paste this in

    Code:
    // com.app.johnstestapp
    // /Applications/John's Test App.app/main.js
    
    Plugins.load( "UIKit" );
    
    ( "first.js" );
    var window = new UIWindow( UIHardware.fullScreenApplicationContentRect );
    window.setHidden( false );
    window.orderFront();
    window.makeKey();
    window.backgroundColor = [ 0 , 1 , 0 , 1 ];
    
    var mainView = new UIView();
    window.setContentView( mainView );
    
    var textbox1 = new UITextField( [ 20 , 50 , 45, 480 ] );
    
    var bar = new UINavigationBar( [ 0 , 0 , 320 , 50 ] );
    bar.showButtonsWithLeftTitle( null , "Start" );
    
    mainView.addSubview( bar );
    
    var itemOne = new UINavigationItem( "Test" );
    bar.pushNavigationItem( itemOne );
    
    bar.onButtonClicked = function ( bar, button )
    {
    if(button == 0)
    {
    include("second.js");
    }
    }
    In second.js copy and paste this in.

    Code:
    // com.app.johnstestapp
    // /Applications/John's Test App.app/main.js
    
    Plugins.load( "UIKit" );
    
    var window = new UIWindow( UIHardware.fullScreenApplicationContentRect );
    window.setHidden( false );
    window.orderFront();
    window.makeKey();
    window.backgroundColor = [ 0 , 1 , 0 , 1 ];
    
    var mainView = new UIView();
    window.setContentView( mainView );
    
    var textbox1 = new UITextField( [ 20 , 50 , 45, 480 ] );
    
    var bar = new UINavigationBar( [ 0 , 0 , 320 , 50 ] );
    bar.showButtonsWithLeftTitle( "Back" , null );
    
    mainView.addSubview( bar );
    
    var itemOne = new UINavigationItem( "Test" );
    bar.pushNavigationItem( itemOne );
    
    bar.onButtonClicked = function ( bar, button )
    {
    if(button == 1)
    {
    include("main.js");
    }
    }

    Hope this helped.

Share This Page