variable and function visibility problem

R

[RaZoR]

hello everybody,

here is my problem: I would like to have scripts that work in parallel.
all of them are controlled and run by main script, namely main.js.
main.js creates the InternetExplorer object (called oIEPipe) with many
variables. oIEPipe is used as a channel that all scripts communicate
through with one another.

0) I have defined an object MyObj as follows:

function MyObj () {
mo = new Object();
var Value;
var setValue = function(arg) { Value = arg; }
var getValue = function() { return Value; }
mo.setV = setValue;
mo.getV = getValue;
return mo;
}

this definition is loaded into main script at the beginning. then main
script creates the communication channel oIEPipe and creates an Array
there. then it runs one of the clients. client looks for the channel
window, finds it and starts to communicate with main script and other
clients through it.

1) when I write in main script:

//definition of MyObj is already loaded
oIEPipe.document.Script.MyArray = new Array();
oIEPipe.document.Script.MyArray[0] = new MyObj();
oWSH.Run("client.js", 2, true);

then client.js sees the object MyObj at MyArray[0] and can execute
(since oIEPipe window has been found) the following statements:

//inside client.js: oIEPipeWindow points to oIEPipe in main script
oIEPipeWindow.document.Script.MyArray[0].setV(3.14159);
oIEPipeWindow.document.Script.MyArray[0].getV();

1A) these changes above are visible when client finishes its work and
returns control to main script, so the latter one can execute
successfully for example:

//in main script, after client finishes
oIEPipe.document.Script.MyArray[0].getV();

And here comes the problem:

but when I write in main script:

//definition of MyObj is or is not loaded
oIEPipe.document.Script.MyArray = new Array();
oWSH.Run("client.js", 2, true);

and create all MyObj objects in client:
//definition of MyObj is already loaded here: client script
oIEPipeWindow.document.Script.MyArray[0] = new MyObj();

then MyArray[0] is visible for client, client can call its
functions, set variables etc. thats ok. but after returning to main
script execution similar to 1A) fails and ends with error:

main.js: the remote server machine does not exist or is unavailable,
code: 800A01CE

I thought that this is because Value is not visible as a part of mo. so
I changed the definition of MyObj() as follows:

function MyObj () {
mo = new Object();
mo.Value;
mo.setValue = function(arg) { mo.Value = arg; }
mo.getValue = function() { return mo.Value; }
return mo;
}

now all functions and variables have the "public" status and are visible
outside. (are they? -- please, correct me if I'm wrong). but it still
ends with error message when returning control to main.js

Is there any solution that allows the following plan of execuion:
main creates channel oIEPipe;
main creates array: oIEPipe.document.Script.myArray = new Array();
main calls client.js;
client.js finds oIEPipe and myArray there;
if some condition is met
client.js creates myArray[sizeofMyArray] = new MyObj();
or
client.js creates its own object ClientObj = MyObj()
and then executes a function AddToArray(MyArray, ClientObj)
client.js calls functions of MyArray[sizeofMyArray] (which is
an MyObj object now), sets values etc.
client returns control to main script
main sees all the changes and can execute MyArray functions
created as part on an object in client.js

I would like all variables and functions being "private" in MyObj()
object if possible and accessible only through priveleged functions like
MyArray.getV()

Is is possible to implement? Please correct me if my thinking is wrong
somewhere.

I would greatly appreciate any sugestions and help..

regards,
[RaZoR]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top