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
Get the mailserver that powers this list at http://www.coolfusion.com
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4