It seems that arguments are passed by values and not by reference.
In fact, in the Utilities.swap methods, o1 and o2 are just fresh copies
of your A & B objects. If you trace o1 and o2 in your swap method,
you'll see that you've successfully swapped o1 and o2, but A and B are
left intact.
You might need to redesign your code by using a reference wrapper or by
encapsulating your objects in a class and create a public method swap()
that will swap its attributes internally.
A little more explanation can be found here (it's as3 related but I
guess it's the same in as2):
http://livedocs.macromedia.com/labs/as3preview/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000044.html
Hope it helps,
Julien Vignali
Alberto Florentin a écrit :
<code>
class Utilities {
public static function swap(o1:Object, o2:Object) {
var tmp:Object=o1;
o1=o2;
o2=tmp;
}
// etc
}
</code>
Somewhere in my code:
<code>
function aFunction(A:aType, B:aType) {
// ...
if (/*some condition*/)
Utilities.swap(A, B);
// ...
}
</code>
But nothing happens. A and B are still the same objects.
Must be missing something...
Alberto
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com