Passing a valid variable object to a function

The problem is simple: I need to pass a valid variable to a function.

private var test:String = "KKK";
trace (" Before --->>> " + test);
testFunction(test);
trace (" Next --->>> " + test);

private function testFunction(d:String):void{
   d = "MMM";
}

Result:

Before --->>> KKK
Next --->>> KKK

The result is correct, but I want to send the current variable testto my function and change it. So I want to have this output:

Before --->>> KKK
Next --->>> MMM

Any solution?

Thanks for your answer, but if I have such code, I need to pass a valid variable to my function:

if ( lastPos == -1 ){// if this is first item 
    flagLEFT = "mid";
    tempImageLEFT = new Bitmap(Bitmap(dataBANK[0]["lineimage" + 10]).bitmapData);
}else if (nextPos == -1){// if this is the last position
    flagRIGHT = "mid";
    tempImageRGHT = new Bitmap(Bitmap(dataBANK[0]["lineimage" + 13]).bitmapData);
}

As you can see, the changes are in flagLEFTand tempImageRGHT. I also have a change on numbers (10 and 13) that can be processed in the usual way. I need something like this:

private function itemFirstLast(flag:String, bmp:Bitmap, pos:int):void{
    flag = "mid";
    bmp = new Bitmap(Bitmap(dataBANK[0]["lineimage" + pos]).bitmapData);
}

Any solution?

0
source share
3 answers

- :

private var test:String = "KKK";
trace (" Before --->>> " + test);
test = testFunction(test);
trace (" Next --->>> " + test);

private function testFunction(d:String):String{
   d = "MMM";
   return d;
}

, . AS3, , :

var object:Object {
   "test":"KKK"
};
trace (" Before --->>> " + object["test"]);
testFunction(object);
trace (" Next --->>> " + object["test"]);

private function testFunction(o:Object):void{
    o["test"] = "MMM";
}
+2

:

class StringValue{
    function StringValue( value : String ) : void{
        this.value = value;
    }
    public var value : String;

    public function toString() : String{
        return value;
    }
}


private var test:StringValue = new StringValue( "KKK" );
trace (" Before --->>> " + test);//traces 'KKK'
testFunction(test);
trace (" Next --->>> " + test);//traces 'MMM'

private function testFunction(d:StringValue):void{
   d.value = "MMM";
}
+2

All Articles