That is absolutely the best explanation I have had so far.
So as3 is only a partially managed language?
For example, if I was to pass the reference to a bitmap object as an
argument to a function, it has to be dereferenced in the function by
instantiating a new variable, and that new variable could be modified
without modifying the original.
I am pretty sure I have it now, and probably sound a little retarded for
reiterating it; yet, if I am wrong please tell me.
Thanks,
Anthony
Juan Pablo Califano wrote:
Well, in AS you don't have pointers (in the sense of C pointers). Except for
primitives, which are basically Number, int, uint, Boolean, and String,
everything else is a reference to an object allocated on the heap.
References in AS behave pretty much like references in Java; and probably
you could think of them as C pointers which you just can assign / reassign
and dereference (you can't do pointer arithmetic on them, you don't have
something like the address-of operator and you just have one level of
indirection).
Even though you'd find the docs say objects are passed by reference, I think
it'd more accurate to say that object references are passed by value (it may
sound a bit pedantic perhaps, but it does make a difference as you can see
in the following examples).
Suppose you have this code:
(list is an Array created outside the function and contains these values
[0,1,2,3] )
function test(list:Array):void {
list.push(4);
}
After the function returns, the contents of list will be [0,1,2,3,4].
You have de-referenced the parameter to access the original Array object and
changed its contents using the push method.
However, since objects are not passed by reference but are rather references
passed by value, if you have this code:
function test(list:Array):void {
list = [0,1,2,3];
list.push(4);
}
After the function returns, the contents of list will be [0,1,2,3] and not
[0,1,2,3,4].
Why? Because the list parameter is just a local variable that holds a
reference to an object. If you de-reference it, you access to the original
object. But if you re-assign it, you have created a new object and stored a
reference to it in that variable. You've lost your link to the original
object. When you access it in the next line, you are now modifiing the
second object, not the object referenced originally in the list parameter.
So, primitives have value semantics; everything else have reference
semantics.
Cheers
Juan Pablo Califano
2008/11/29 Anthony Pace [EMAIL PROTECTED]
Is there a list of what is referred to as a pointer for the AS3 spec, and
what when a value is just duplicated?
This would be useful to have. Took me a few moments to realize that
most(if not all) objects on the display list are actually pointed to when
passing a reference to them as a argument.
If you know what I am looking for your would be appreciated.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders