facebook

Execute functions based on Screen ID: CLOSED

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

    davidg
    Member

    Hi,

    I have a question:

    I need a function to execute when a particular screen loads but I’m not sure how to do that.

    For example, here is my function that I placed in the _custom.js at the very top:

    var myVar1=setInterval(function(){myTimer1()},2000);

    As expected myTimer1 executes every 2 seconds no matter what screen is being used. However I only want it to run when I’m on screen 2.

    I assume I will be using:

    phoneui.postPageTransition = function(newScreenId) {}

    But I don’t know how to use this in order to get it to work properly.

    Thanks in advance for the help.

    #338953 Reply

    Stu Wade
    Member

    Hi David,
    I’ve never used the postPageTransition function, but I use the prePageTransition extensively, so assuming they work in the same fashion, my code in the page transition function looks like:

    if(currentScreenId==’#m1-ChicagoPlayers’){ insert custom code };

    Hope this helps

    #338956 Reply

    Hi David,

    As Stu has stated, you need to compare in the postPageTransition function what screen is the new current screen. So, I sugest you to use something like this:

    var timer1;
    var timer2;
     
    phoneui.postPageTransition = function(newScreenId) {
      if(newScreenId=="#m1-screen1"){
          timer1 = setInterval(function(){myTimer1()},2000);
          window.clearInterval(timer2); // stop timer2
      }
       else if(newScreenId=="#m1-screen2"){
          timer2 = setInterval(function(){myTimer2()},2000);
          window.clearInterval(timer1); // stop timer1
      }
    }

    In case you have more screens you should add more else if blocks code, and stop all others timers in each block. e.g. if you add a third screen you should also stop timer3 in first block of code, of course you have to add it in your code too:

      if(newScreenId=="#m1-screen1"){
          timer1 = setInterval(function(){myTimer1()},2000);
          window.clearInterval(timer2); // stop timer2
          window.clearInterval(timer3); // stop timer3
      }

    Hope this is helpful for you.

    #339005 Reply

    davidg
    Member

    @support-octavio

    Thanks for the help. The code works for all my screens except one. I can’t figure out why. I simplified it to:

    phoneui.postPageTransition = function(newScreenId) {
      if(newScreenId=="#m1-86-Air"){
       window.alert("hey");
      }
    }

    But for some reason “Hey” doesn’t appear on screen “86-Air” when I go to it as it did with other screens.

    This screen contains a multipage widget, I don’t know if that is throwing it off or not.

    Any thoughts?

    Thanks

    #339022 Reply

    Stu Wade
    Member

    Just a random thought, there have been reports (see: strange behaviours in naming a screem) in this forum that sometimes hyphens in screen names get transformed to underscores in the HTML and js files. A quick check of these files will confirm or deny whether this is the case here.

    #339042 Reply

    davidg
    Member

    Hi Stu,

    That was a good idea to try but it didn’t work.

    I changed file to “86Air” instead of “86-Air” and it didn’t seem to work. The Alert on screen transition still didn’t work for that screen.

    I’ll play around with a few things to see if I can’t figure out why it’s not working. I am now thinking it might be the multipage widget messing things up.

    Thanks

    #339045 Reply

    Stu Wade
    Member

    May I suggest:

    In your postTransition code insert a debug alert to state where the code believes itself to be. Something like

    alert(‘currentPageId=’+currentPageId);

    I have a sneaking suspicion that the answer will be #m1-Project-multiPagePage.

    #339060 Reply

    Hi David,

    When you use dashes (-) in the name of your designs, Mobione’s Codegen replaces them for underscores(_). So your code must be similar to next:

    phoneui.postPageTransition = function(newScreenId) {
      if(newScreenId=="#m1-86_Air"){
       window.alert("hey");
      }
    }
    #339117 Reply

    davidg
    Member

    Hi, support-octavio

    You and Stu were right about the dash changing to underscore. I ended up removing the dash all together and still had the problem. I then removed the “86” and it worked great. Just to be sure I tried using other numbers and it stopped working again.

    My conclusion is that dashes get converted to underscores like you said, and that numbers don’t work in the name when using the phoneui.prePageTransition.

    Just thought I would update you guys on how it turned out.

    Thanks for all the help.

    #339118 Reply

    harry045
    Member

    I’ve never used the postPageTransition function, but I use the prePageTransition extensively, so assuming they work in the same fashion, my code in the page transition function looks like:

    #339119 Reply

    davidg
    Member

    @harry045 wrote:

    I’ve never used the postPageTransition function, but I use the prePageTransition extensively, so assuming they work in the same fashion, my code in the page transition function looks like:

    Im Sorry I meant prePageTransition not postPageTransition in my earlier post.

    #339560 Reply

    davidg
    Member

    Thanks guys, I just now realized I never responded to this thread.


    @support-octavio
    , your post helped me the most. I worked well.

    #339631 Reply

    Hi David,

    Thanks for your follow up. I’m glad to help. Thread closed.

Viewing 13 posts - 1 through 13 (of 13 total)
Reply To: Execute functions based on Screen ID: CLOSED

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