Turns out the problem was based on 3 developers working on related code at
the same time.  Once we got them sorted out, the problem disappeared...

Thanks anyway.

Shawn

-----Original Message-----
From: Shawn Grover [mailto:[EMAIL PROTECTED]
Sent: Friday, February 28, 2003 2:29 PM
To: CF-Talk
Subject: OT: Javascript object reference problem


Need some help with this one - it appears our objects are loosing their
memory references when we pass them between windows.

Here's the scenario:

1) On the main page, we declare an instance of a javascript class (which we
created).
2) The main page opens a pop-up window which takes in some information, and
stores it in an object local to the popup window.  Next, the code passes the
object to a function in the object on the main window (addObject();).  The
addObject() function creates a new local version of the object, and
populates it's properties based on the values of the passed object, then it
adds the object to an array.

The problem is that when we pass the object to the function, once inside the
function, the object has no values - as if the object lost it's reference.
I've include some sample code below, but everything I've seen says this
should be valid.  So, I'm looking for suggestions - google wasn't too much
help in this case.  Thanks for any assistance that can be offered.


Sample Code - Class definition:

        function MyObjectAddObject(oObject) {
                var oNewObj = new SubObject();
                oNewObj.ID = oObject.ID;
                oNewObj.Name = oObject.Name;

                this.ObjectList[this.ObjectList.length] = oNewObj;
                return oNewObj;
        }

        //constructor
        function MyObject() {
                this.ObjectList = new Array();          //collection of
objects
                this.Name = "";

                //methods
                this.AddObject = MyObjectAddObject();
        }

Sample Code - Main Page

        <script>
                var oMyObject = new MyObject();

                function OpenPopUp() {
                        . . . 
                }
        </script>


Sample Code - Popup Window

        <script>
                var oMyObjRef = window.opener.oMyObject;
                var oLocalObj = new SubObj();

                PopulateSubObjectFromForm();
                
                // NOTE 1:  both object references are valid at this point.
                oMyObjRef.AddObject(oLocalObj);

                // NOTE 2: we used alerts before, after and inside the
function to demonstrate things are functioning, correctly.
                //  inside the function, the passed object becomes empty,
and the properties are null.
        </script>

Thanks again for any help you can offer.


Shawn

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Your ad could be here. Monies from ads go to support these lists and provide more 
resources for the community. http://www.fusionauthority.com/ads.cfm

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
                                

Reply via email to