variable and function visibility problem

Discussion in 'Javascript' started by [RaZoR], Sep 2, 2003.

  1. [RaZoR]

    [RaZoR] Guest

    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]
    [RaZoR], Sep 2, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Wark
    Replies:
    1
    Views:
    598
    Brock Allen
    May 23, 2005
  2. Steve Wark

    Variable Scope / Visibility

    Steve Wark, May 23, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    467
    Steve Wark
    May 23, 2005
  3. COHENMARVIN
    Replies:
    2
    Views:
    638
    Lucas Tam
    Sep 12, 2005
  4. visibility of variable

    , Sep 26, 2005, in forum: C Programming
    Replies:
    14
    Views:
    528
    Keith Thompson
    Sep 27, 2005
  5. Replies:
    8
    Views:
    409
    James Kanze
    Apr 4, 2009
Loading...

Share This Page