|
|
|
Philips Pronto Professional Forum - View Post
|
|
|
|
|
|
|
The following page was printed from RemoteCentral.com:
Topic: | How to define libraries This thread has 6 replies. Displaying all posts. |
|
Post 1 made on Wednesday August 11, 2010 at 05:39 |
Drewi Long Time Member |
Joined: Posts: | August 2010 11 |
|
|
Hi all on Remote central Pronto Professional Forum,
I've found many helpfull hints here so long, but I have not found a solution for my current problem: For using functions in any activity I want to place the code in a library. The functions should control some device status widgets on the system page. I want to call these functions from every activity which may change the status of the devices. The name of library is 'com.my.status1'. Included is current one only function 'updateStatus()' I want to call the function from an activity by
System.include('com.my.status1.js'); var lib = com.my.status1 lib.updateStatus();
In the library I have tried to define the namespace (how described in the d.g. example) as follows:
var com; if (!com) { com = {}; } else if (typeof com !== "object") { throw new Error("com already exists and is not an object"); } if (!com.my) { com.my = {}; } else if (typeof com.my !== "object") { throw new Error("com.my already exists and is not an object"); } if (com.my.status1) { throw new Error("com.my.status1 already exists"); } com.my.status1 = {};
This gets me the error message 'com.my.status1 already exists'.
Mybe I don't understood how libraries work?!
Has anybody a usefull hint for me? Thanks for any ideas.
Drewi
|
|
Post 2 made on Wednesday August 11, 2010 at 06:21 |
Guy Palmer Active Member |
Joined: Posts: | June 2008 648 |
|
|
I'm not clear what all that code is trying to achieve. I just dragged and dropped my global library into the relevant tab of system properties and then all the functions it contained were automatically available in all activities.
|
|
Post 3 made on Wednesday August 11, 2010 at 06:33 |
sWORDs Long Time Member |
Joined: Posts: | November 2006 373 |
|
|
When using System.include make sure that the library is unchecked (or keep it checked and don't include).
|
|
|
OP | Post 4 made on Wednesday August 11, 2010 at 09:06 |
Drewi Long Time Member |
Joined: Posts: | August 2010 11 |
|
|
Thank you guys for your quick answers. After reading that is seems I think to complicated... So I have reduced my library code to
statusUpdate = function() { ... }
Nothing else. I draged my library (status1.js) on the property system page and checked it. The call 'status1.statusUpdate()' gives me the error message now 'ReferenceError: status1 is not defined'. Thank you for your hints... Drewi
|
|
Post 5 made on Wednesday August 11, 2010 at 10:09 |
sWORDs Long Time Member |
Joined: Posts: | November 2006 373 |
|
|
Use statusUpdate() instead of status1.statusUpdate(). Or change statusUpdate = function(){} to
status1={}; status1.statusUpdate=function(){};
But I would recommend using a namespace as you did before and then call with com.my.status1.statusUpdate().
|
|
|
OP | Post 6 made on Wednesday August 11, 2010 at 11:47 |
Drewi Long Time Member |
Joined: Posts: | August 2010 11 |
|
|
It works! Thank you sWORDs... To increase my skills in coding libraries - what's wrong in the namespace code in my first post? Is there a special function declaration needed?
|
|
Post 7 made on Thursday August 12, 2010 at 00:44 |
Lyndel McGee RC Moderator |
Joined: Posts: | August 2001 12,992 |
|
|
Drewi,
I think that what is wrong (as SWORDS has pointed out) is that in PEPv2, you checked your library (selected the checkbox) either in System Properties or Activity Properties which automatically causes the library to be loaded (what you are doing with System.include). You then issued System.include on your JS file causing the file to be executed 2 times (you can accomplish the same thing by doing System.include 2+ times on your JS file). You can do one or the other but not both.
If using System.include, don't check the library for sure at the system level and don't check it for sure at the activity level.
Note that System.include() was provided for use earlier prior to Philips adding the 'Library' selection as part of the editor.
|
Lyndel McGee Philips Pronto Addict/Beta Tester
|
|
|
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.
|
|
|
|