- This topic has 12 replies, 4 voices, and was last updated 11 years, 5 months ago by support-octavio.
-
AuthorPosts
-
davidgMemberHi,
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.
Stu WadeMemberHi 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
support-octavioMemberHi 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.
davidgMemberThanks 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
Stu WadeMemberJust 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.
davidgMemberHi 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
Stu WadeMemberMay 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.
support-octavioMemberHi 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"); } }
davidgMemberHi, 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.
harry045MemberI’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:
davidgMember@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.
davidgMemberThanks guys, I just now realized I never responded to this thread.
@support-octavio, your post helped me the most. I worked well.
support-octavioMemberHi David,
Thanks for your follow up. I’m glad to help. Thread closed.
-
AuthorPosts