code_junkie

Can you have “ByRef” arguments in AS3 functions?

Nov 12th, 2011
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. Sub do (ByRef inout As Integer)
  2. inout *= 5;
  3. End Sub
  4.  
  5. Dim num As Integer = 10
  6. Debug.WriteLine (num) '10
  7. do (num)
  8. Debug.WriteLine (num) '50
  9.  
  10. return {a:"string 1", b:"string 2"}
  11.  
  12. function func(a:String){
  13. a="newVal";
  14. }
  15.  
  16. var b:String = "old";
  17.  
  18. trace(b) // old
  19. func(b);
  20. trace(b) // old
  21.  
  22. function Test(a:Object, b:Object):void {
  23. a = b;
  24. }
  25.  
  26. funtion Test2():void {
  27. var s1:Sprite = null;
  28. var s2:Sprite = new Sprite;
  29.  
  30. Test(s1,s2);
  31. Trace(s1);
  32. Trace(s2);
  33. }
  34.  
  35. null
  36. [object Sprite]
  37.  
  38. function Test(a:Object, b:Object):void {
  39. a = b;
  40. }
  41.  
  42. var s1:Sprite = null;
  43. var s2:Sprite = new Sprite;
  44. Test(s1,s2);
  45.  
  46. function passByRef(objParam:Object):void
  47. {
  48. objParam.x++;
  49. objParam.y++;
  50. trace(objParam.x, objParam.y);
  51. }
  52. var objVar:Object = {x:10, y:15};
  53. trace(objVar.x, objVar.y); // 10 15
  54. passByRef(objVar); // 11 16
  55. trace(objVar.x, objVar.y); // 11 16
Add Comment
Please, Sign In to add comment