facebook

How to have a Random Page? CLOSED

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 7 posts - 16 through 22 (of 22 total)
  • Author
    Posts
  • #347089 Reply

    Brandon
    Member

    My code was for a multipage widget, it sounds like you are just wanting to go to a new page, not a multipage widget.

    If thats true use the phoneui.gotoPage(‘m1-page1’);
    Also make sure you didnt delete an needed brackets or anything else.
    If you can post your actual code it could help if this does not work.

    #347107 Reply

    johnjohn
    Member

    Hi Brandon, thank you very much for your response.

    Yes, not a multipage widget. I am try to have clicking on a button in my main page (main.mobi) to go to any of 5 pages (page1.mobi etc) randomly.

    Here is my code but it’s not working

    
    n = Math.floor((Math.random()*5)+1);
    switch(n)
    {
    case 1:
     phoneui.gotoPage(  'm1-page1',  phoneui.transitions.slideLeft);
      break;
    case 2:
     phoneui.gotoPage( 'm1-page2',  phoneui.transitions.slideLeft);
      break;
    case 3:
     phoneui.gotoPage( 'm1-page3',  phoneui.transitions.slideLeft);
      break;
    case 4:
     phoneui.gotoPage( 'm1-page4',  phoneui.transitions.slideLeft);
      break;
    case 5:
     phoneui.gotoPage( 'm1-page5',  phoneui.transitions.slideLeft);
      break;  
    }
    
    

    This is probably very basic for you, but could you help me as I am new to programming. I tried to watch MobiOne related videos on youtube and read up on the Learning Centre but could not find the solution. Thanks.

    #347231 Reply

    Brandon
    Member

    Try using: return; instead of break; and see if that helps. Ive had break return errors for some reasons.

    #347315 Reply

    johnjohn
    Member

    Hi Brandon,

    It’s still not working for me. Anyway thanks for your help.

    #347431 Reply

    Hi johnjohn,

    You could use a similar code to this:

    var n = Math.floor((Math.random()*2)+1);
    
    var screens = {
     1 : "m1-two",
     2 : "m1-three"
    };
    
    phoneui.gotoScreen(screens[n], 'FADE');
    #347445 Reply

    johnjohn
    Member

    This finally worked!. Thanks a lot for the help.

    #347480 Reply

    Hi johnjohn,

    That’s great, thanks for closing the loop.

Viewing 7 posts - 16 through 22 (of 22 total)
Reply To: How to have a Random Page? CLOSED

You must be logged in to post in the forum log in