Created
March 15, 2013 13:05
-
-
Save creynders/5169757 to your computer and use it in GitHub Desktop.
in response to http://stackoverflow.com/questions/15432131/pass-by-reference-is-not-working-in-actionscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package passByReference | |
{ | |
/** | |
* @author creynder | |
*/ | |
public class PassByReference{ | |
public function PassByReference() | |
{ | |
var receiver : Receiver = new Receiver(); | |
trace( receiver.counter ); //outputs "1" | |
setCounter( receiver ); | |
trace( receiver.counter ); //outputs "10" | |
} | |
private function setCounter( receiver : Receiver ) : void{ | |
receiver.counter = 10; | |
} | |
} | |
} | |
internal class Receiver{ | |
public var counter : int = 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment