I'm pretty positive what I want to do isn't possible with ActionScript, but it would be nice to be wrong.
I need to pass a variable reference to a function, and have the function change the value of the variable.
So, simplified and not in completely correct syntax, something like this:
function replaceValue(element:*, newValue:String):void
{
element = newValue;
}
var variableToModify:String = "Hello";
replaceValue(variableToModify, "Goodbye");
trace(variableToModify) // traces value of 'Hello', but want it to trace value of 'Goodbye'
Of course, in the replaceValue function, element
is a new reference to fungibleValue
(or, rather, a new reference to fungibleValue
's value). So, while element
gets set to the value of newValue
, fungibleValue
does not change. That's expected but totally not what I want, in this case.
There's a similar question, for Ruby, here http://stackoverflow.com/questions/2155335/changing-value-of-ruby-variables-references
As the question points out, Ruby has a way to accomplish this. BUT is there any way to do this in ActionScript?
If so, it's going to make something stupid a lot easier for me.