facebook

How to have a Random Page? CLOSED

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

    kevin94
    Member

    Hello i am new here, and i registered me here because i couldn’t find any help in the internet.

    My problem is:
    I want to run a JavaScript Code in MobiOne, that opens random pages.

    So if i would klick on a Button where stands: “Random”
    i would to have a Random page (from 10 pages)
    if it is important: all the 10 pages are in one multipage.

    Please could someone poste me the example code, i really need help.
    Thanks so much.

    PS: Sorry for my bad english. -.-

    #337482 Reply

    Brandon
    Member

    Not the only way to do it, but here is one way.
    First create your multipage form and the button.
    Then inside the button action select run javascript.
    In side the javascript you will need something like this:

    
    //Untested Code
    //random 1 to 10
    n = Math.floor((Math.random()*10)+1);
    switch(n)
    {
    case 1:
     phoneui.gotoMultiPagePage('m1-yourform-multiPage1', 'SET_PAGE', 'm1-yourform-page1',  phoneui.transitions.slideLeft);
      break;
    case 2:
     phoneui.gotoMultiPagePage('m1-yourform-multiPage1', 'SET_PAGE', 'm1-yourform-page2',  phoneui.transitions.slideLeft);
      break;
    case 3:
     phoneui.gotoMultiPagePage('m1-yourform-multiPage1', 'SET_PAGE', 'm1-yourform-page3',  phoneui.transitions.slideLeft);
      break;
    case 4:
     phoneui.gotoMultiPagePage('m1-yourform-multiPage1', 'SET_PAGE', 'm1-yourform-page4',  phoneui.transitions.slideLeft);
      break;
    case 5:
     phoneui.gotoMultiPagePage('m1-yourform-multiPage1', 'SET_PAGE', 'm1-yourform-page5',  phoneui.transitions.slideLeft);
      break;
    case 6:
     phoneui.gotoMultiPagePage('m1-yourform-multiPage1', 'SET_PAGE', 'm1-yourform-page6',  phoneui.transitions.slideLeft);
      break;
    case 7:
     phoneui.gotoMultiPagePage('m1-yourform-multiPage1', 'SET_PAGE', 'm1-yourform-page7',  phoneui.transitions.slideLeft);
      break;
    case 8:
     phoneui.gotoMultiPagePage('m1-yourform-multiPage1', 'SET_PAGE', 'm1-yourform-page8',  phoneui.transitions.slideLeft);
      break;
    case 9:
     phoneui.gotoMultiPagePage('m1-yourform-multiPage1', 'SET_PAGE', 'm1-yourform-page9',  phoneui.transitions.slideLeft);
      break;
    case 10:
     phoneui.gotoMultiPagePage('m1-yourform-multiPage1', 'SET_PAGE', 'm1-yourform-page10',  phoneui.transitions.slideLeft);
      break;
    }
    
    
    
    #337537 Reply

    kevin94
    Member

    YES, Thank you so much its working! 😀

    #337544 Reply

    Brandon
    Member

    You’re welcome, glad its working for you.

    #339836 Reply

    Rathinavel
    Member

    Hi,

    it works for changing only one page at any instant….

    I want to show that there are two pages being changed in one single button click, how can i do it.

    Here is my Code,

    refreshPage= function()
    {
    phoneui.gotoMultiPagePage(‘m1-proj1-mulpgTableOfContents’, ‘SET_PAGE’, ‘m1-proj1-pgMaterials’, phoneui.transitions.slideRight);

    phoneui.gotoMultiPagePage(‘m1-proj1-mulpgMainMenu’, ‘SET_PAGE’, ‘m1-proj1-page1’, phoneui.transitions.slideRight);
    }

    In the above code,

    The first line alone works good but not the second line.

    immediate help is really appreciated 🙂

    Warm Regards,
    Vel.

    #339838 Reply

    Brandon
    Member

    You have two options.
    1. You can use the post page transition, but this would only be if you want it to go to the second page every time.

    2. (What I would probably do) You could use a timer to to call the second page after a few seconds when the first page is done.

    //start timer: 2 seconds
    var myVar=setInterval(function(){myTimer()},2000);

    function myTimer()
    {
    //after the 2 seconds go to the second page
    phoneui.gotoMultiPagePage(‘m1-proj1-mulpgMainMenu’, ‘SET_PAGE’, ‘m1-proj1-page1’, phoneui.transitions.slideRight);
    //clear the timer so it doesnt do it again
    clearInterval(myVar);
    }

    #339855 Reply

    Rathinavel
    Member

    Thanks alot Cincy Planet 🙂

    It worked like a charm 🙂 🙂 🙂

    Excited to see it working 😀 wow… :d

    but One small problem…

    I have a home button in page 3(BlogPost). when i click it, it should come to 2nd page(Main Contents) and then 1st page(Home).

    Now what happens is the page transition happens, even if I go from 1st page to 2nd page, this once again goes to the 1st Page.. 🙁

    cant this be restricted to only on click of the Home button…!?!

    #339871 Reply

    Brandon
    Member

    You can call it from in a function:

    function callTimer()
    {myVar=setInterval(function(){myTimer()},2000);
    }

    then in the run javascript of any button or any where you need it just call that function.

    #339890 Reply

    Rathinavel
    Member

    It Works..!

    Thanks a lot once again Cincy Planet 🙂

    Day by day my love for MobiOne is Growing 🙂

    #339907 Reply

    Brandon
    Member

    Good to hear. Yes, there isn’t too much M1 can’t do. My latest app that was just released had a puzzle and a uses face detection for a fun feature (see the app showcase section).

    #339913 Reply

    Rathinavel
    Member

    Hi Cincy Planet,
    I will have a look at my home (as my sister has the iPhone), and give you the review when I had used it 🙂

    nice to hear that you had developed a puzzle out of MobiOne… I’m Curious 🙂

    Warm Regards,
    Vel.

    #339914 Reply

    Brandon
    Member

    There is an Android version I just posted also.

    #339950 Reply

    Rathinavel
    Member

    Hi CincyPlanet,

    I had a look at the android Version of the app.

    Jessica Cameron Fan app (really it is).

    its looking too good in look and feel 🙂

    #342909 Reply

    temahant
    Member

    at me it didn’t turn out (
    give please mobi the file

    #347082 Reply

    johnjohn
    Member

    I followed the example by CincyPlanet but I couldn’t get it to work.

    My intention is my main file (main.mobi) has a button whereby pressing will randomly bring up any one of 5 pages (page1.mobi, page2.mobi etc).

    The main changes i made to the code posted by CincyPlanet was
    n = Math.floor((Math.random()*10)+1);
    change to
    n = Math.floor((Math.random()*5)+1)

    and

    phoneui.gotoMultiPagePage(‘m1-yourform-multiPage1’, ‘SET_PAGE’, ‘m1-yourform-page1’, phoneui.transitions.slideLeft);
    change to
    phoneui.gotoMultiPagePage(‘m1-main’, ‘SET_PAGE’, ‘m1-page1’, phoneui.transitions.slideLeft);

    and delete all code from “case 6:” to “break;”

    I am very new to programming and would appreciate some guidance.

    Thanks.

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

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