Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Previous section Next section Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Topic:
Purpose of onEntryCallback?
This thread has 11 replies. Displaying all posts.
Post 1 made on Tuesday February 2, 2010 at 13:55
eht123
Long Time Member
Joined:
Posts:
September 2008
33
Anyone have any idea what the purpose of the onEntryCallback function is? How is it any different from the activity script itself, which runs on entry already?
Post 2 made on Wednesday February 3, 2010 at 00:59
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
If you are writing a library, you can do things like:

CF.activity().onEntry= function(){
// inside this function, keyword 'this' is the activity.

this.x=234; // works same as declaring a var in activity script.

};

What this allows is for you to declare variables for an activity in the library and therefore hide things such that users cannot modify them or screw things up.

Same applies for onExit which is a cleanup function where you can remove things.

Also note that pages support this as well where you can do such things as installing FirmKey handlers, create/destroy dynamic widgets, etc...

CF.activity().page('MyWellKnownPage').onEntry = function()
{
// install Firm1 press handler when page is started.
GUI.widget('PS_FIRM1').onPress= function(){
System.print('Firm1 Pressed');
};
// create dynamic widgets if you wish. (this keyword references current page)
this.w = GUI.newPanel(); // hope my syntax is right.
}

CF.activity().page('MyWellKnownPage').onExit = function()
{
// remove Firm1 press handler when page is exited.
GUI.widget('PS_FIRM1').onPress= null;
GUI.deleteWidget(this.w); // this is likely incorrect but put here to illustrate point.
this.w = null;
}
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 3 made on Wednesday February 3, 2010 at 22:48
eht123
Long Time Member
Joined:
Posts:
September 2008
33
Interesting, thanks.
Post 4 made on Thursday February 4, 2010 at 18:48
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
WARNING - This post is NOW incorrect based on information surfaced later in this thread. page 104 of latest Dev Guide.

Another interesting point about Page.onEntry/onExit is that they are called exactly once, even if the page script is repeated.

so, for a page, logic is...

Just after page is loaded such that all GUI widgets are available,
remote does the equivalent of:

if (page.onEntry)
page.onEntry.call(thisPage);

Then, remote executes any script in the page, repeating if user desires based on pageInterval.

Then, just prior to leaving said page
remote does equivalent of :

if (page.onExit)
page.onExit.call(thisPage);

Last edited by Lyndel McGee on September 6, 2010 20:54.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 5 made on Monday September 6, 2010 at 17:50
johnmack
Long Time Member
Joined:
Posts:
October 2005
42
Apologies for resurrecting an old thread but I've encountered a problem with page.onEntry that contradicts what has been written here.

I've been replacing some initialisation code in my page scripts with equivalent page.onEntry code at activity level. This has had the effect of causing my page scripts to fail and me to pull my hair out until I read the following in the Developer's Guide on page 104.

"The function will be called after execution of the page script, if any"

My problem was that I was setting up a couple of variables in the onEntry function that were used in the page script and, as the page script is called first, it was failing.

Whilst I can go back to my initialisation code, I don't understand why it has been done this way. 

Any thoughts?

John 
Post 6 made on Monday September 6, 2010 at 19:54
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
JohnMAck, you are absolutely correct. But the reason is fairly obvious (at least to me after I thought about it). If they attempted to execute an onEntry defined in the body of the page script before they executed the page script it would not yet be defined!! Ergo they must execute the pagescript to establish the definition and then they can execute it.

Now I guess they can recognize that they just defined the onEnytry function in the middle of the page script and then immediately execute it but that would be less elegant, maybe more to somes liking but less elegant.
Post 7 made on Monday September 6, 2010 at 20:53
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
Well, I stand corrected. Previous post edited.

Thanks for the followup.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 8 made on Wednesday September 8, 2010 at 03:50
buzz
Super Member
Joined:
Posts:
May 2003
4,366
onEntry() fills out the tool kit a little. At the activity level, Library code is loaded first, includes are loaded on demand, and onEntry() is executed last. onEntry() is slightly different because it is a function while the other facilities simply copy text.

While heavily "class" oriented programmer would want to define a page class with a start-up constructor, I think that onEntry() is a clean construct to initialize a page loop. I always thought that fussing with an activity global variable or a System global to initialize a page loop was inelegant.

Overall, I spend a major part of my coding time working around the lack of a truly global scope. Yes, moving to a global scope model at this point would introduce potential compatibility issues with existing code, but this could be handled with an "advanced" or "executive" mode switch at the editor level. In "executive" mode onEntry() is a very clean construct.
Post 9 made on Wednesday September 8, 2010 at 12:56
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
Could you expand on that last paragraph. It has me a bit confused.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 10 made on Saturday July 23, 2022 at 10:22
randman
Long Time Member
Joined:
Posts:
June 2003
416
In a Javascript library, I need to define a callback that is called whenever ANY page in the Activity is entered. So, this would seem to be a good use of:

CF.activity().page('MyWellKnownPage').onEntry = function() {
...
}

However, in the library, I don't want to assume what the names of pages are. Is there a way to add onEntry page callbacks if I don't want to assume ahead of time what the page names are going to be? Or maybe a way to get the list of pages in an activity, and then define the onEntry callback for each of the pages?
Post 11 made on Monday July 25, 2022 at 22:45
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
I wish it were supported but it is not. There is no way to enumerate/list activities, pages, or widgets. I requested it but oh well, was not in the stars.

You must know the ProntoScript name (tag) of the item you want to hook.

:-(
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 12 made on Monday July 25, 2022 at 23:06
randman
Long Time Member
Joined:
Posts:
June 2003
416
On July 25, 2022 at 22:45, Lyndel McGee said...
I wish it were supported but it is not. There is no way to enumerate/list activities, pages, or widgets. I requested it but oh well, was not in the stars.

You must know the ProntoScript name (tag) of the item you want to hook.

:-(

Ah, thanks. I was afraid that was the answer, since your example from an old post used the name "MyWellKnownPage".


Jump to


Protected Feature Before you can reply to a message...
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now.

Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.

Hosting Services by ipHouse