Can you have "ByRef" arguments in AS3 functions?

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

Something like VB.NET where you can change the input argument variable (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

Nothing but an associative array return?

return {a:"string 1", b:"string 2"}
+5
source share
6 answers

Everything in AS3 is a link other than [u] ints. To summarize, everything that inherits Objectwill be assigned to the function by reference.

, , , , - , Array String ( "5", + ).

+3

googled:

ActionScript 3.0 , . , , Boolean, Number, int, uint String, , , .

.

+15

, , ints, units, Booleans . Flash, :

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

var b:String = "old";

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

... String ? ? , , ?

+6

Wrong Wrong and Wrong.. !!! , , , .

function Test(a:Object, b:Object):void {
   a = b;
}

function Test2():void {
   var s1:Sprite = null;
   var s2:Sprite = new Sprite;

   Test(s1,s2);
   Trace(s1);
   Trace(s2);
}

:

null
[object Sprite]
+2

, C-, .

, - , "bob from (bob = new person();)" , , , .

, ,

function Test(a:Object, b:Object):void {
   a = b;
}

, "a" "b" , "Test" "a" , "b" - .

var s1:Sprite = null;
var s2:Sprite = new Sprite;
Test(s1,s2);

, s1 s2 "null" " " , s1 s2 "Scope" < - , , .

"a" , "null" "b" , " , s2". , , , "a" "b" / " " "a" "b" , , , "s1" "s2" , .

, , "a" "b" , , , , "a" , "b" . "s1" "s2" , .

!!!! , "a" "b" , "s1" "s2" , , "a" "b" ,.

+2

DarthZorG Flash:

function passByRef(objParam:Object):void 
{ 
    objParam.x++; 
    objParam.y++; 
    trace(objParam.x, objParam.y); 
} 
var objVar:Object = {x:10, y:15}; 
trace(objVar.x, objVar.y); // 10 15 
passByRef(objVar); // 11 16 
trace(objVar.x, objVar.y); // 11 16

Point Being: You cannot change what the link refers to, but you can change the data referenced by the link as long as the link is an object / array.

0
source

All Articles