;

PDA

Click to See Complete Forum and Search --> : Pointers


ninjakannon
01-18-2009, 11:17 AM
Say I create 2 sprites.

var s1:Sprite = new Sprite();
var s2:Sprite;

Then I set s2 = s1. Now, when I alter any properties of either s1 or s2, the property of both instances changes.

So what is s2? s1 is a sprite instance, is s2 also a sprite instance or simply a pointer to the sprite instance s1?

Thanks!

renderhjs
01-18-2009, 11:59 AM
this is how I think it works,- somewhere a sprite class gets adressed (in your ram, in the CPU in the logic- dunno where exactly). Booth s1 and s2 are in your case pointers to that class that is stored somewhere.

once you null booth variables (e.g s1 = null) the garbage collector will at some point sweep and delete the original sprite class from your ram,logic ect.

However pointers only are used with advanced types such as objects, classes and arrays. Numbers and integers are a acception. Or something like that- there should be a adobe documentation about this.

ninjakannon
01-18-2009, 12:37 PM
That would actually be a good way of doing it - minimising the RAM used. So perhaps you're right; good thinking!

I would expect there is some documentation about this somewhere, although I can't find any. Would be nice if someone knew where that was, or what happens for sure.

5TonsOfFlax
01-18-2009, 01:35 PM
Yes, that's how it works. It's very like Java in that respect where everything other than primitives (Number, int, etc) are handled as references.

I don't have a link to specific documentation, but I'm 99.9999% certain that's how things work.

ninjakannon
01-18-2009, 03:07 PM
Awesome, that's brilliant. Thanks for the info guys!