PDA

View Full Version : Pointers and references



bergheim
June 26th, 2004, 01:20 PM
Hello.
Is there any way to get the address of a variable etc like in c/c++?

Like:
var someRef = &_root.as['someVar'];

or

function whatnot( var *someVar ) { ... }

My initial tests shows that flash makes copies of everything, even selfsefined objects! Surely there must be support for something else...

ScriptFlipper
June 27th, 2004, 06:20 AM
I have no experience of c/c++, so I will give you a link to a post in the "Best of kirupa.com"-thread!

http://www.kirupaforum.com/forums/showthread.php?t=12082

jetset
June 27th, 2004, 06:50 AM
actually any nonprimitive type assignment is just a reference and Not a copy:

var obj = new Object();
obj.name = "dude";

var obj2 = obj;
trace(obj2.name); // proves nothing could still be a copy

obj2.name = "dude2";
trace(obj.name);// original has changed
changeName(obj);
trace(obj2.name);// and even after the function call
trace(obj.name);

function changeName(obj)
{
obj.name = "newName";
}

// Cheers, J