Can you have “ByRef” arguments in AS3 functions?

Any idea how to return multiple variables from a function in ActionScript 3?

Anything like VB.NET where you can have the input argument's variable modified (ByRef arguments)?

Sub do (ByRef inout As Integer)
 inout *= 5;
End Sub

Dim num As Integer = 10
Debug.WriteLine (num)        '10
do (num)
Debug.WriteLine (num)        '50


Anything apart from returning an associative array?

return {a:"string 1", b:"string 2"}

Answers


Everything in AS3 is a reference aside from [u]ints. To generalize, everything that inherits Object will be given to the function by a reference.

That being said, the only way I believe you can do it is use a container class like an Array or a String ("5" and do the conversion+math).


Quoting a googled source:

In ActionScript 3.0, all arguments are passed by reference because all values are stored as objects. However, objects that belong to the primitive data types, which includes Boolean, Number, int, uint, and String, have special operators that make them behave as if they were passed by value.

Which led me to look up the canonical source.


It appears that Strings, ints, units, Booleans are passed by Value. I tried this little snippet in Flash and the results were negative:

function func(a:String){
    a="newVal";
}

var b:String = "old";

trace(b)    //  old
func(b);
trace(b)    //  old


So... is String a blacklisted data type too? Boolean too? I mean whats a sure way of telling which types are passed by reference?


Need Your Help

GWT - how to set an entry point method for all incomming requests in RPC servelet

java web-services gwt

I have a RemoteServiceServlet class implements several services (methods).

Show gap of missing data with Highstock

javascript highcharts highstock

Using Highstock to chart a sorted time serie: [[timestamp, value], ...]