• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 142
  • Last Modified:

Passing values ByRef, CONSTANTS in AS 2.0

Is there any way to pass variables ByRef (by reference, rather than by value) in AS 2.0? I need to modify several variables of various data types in a function I call. I don't want to declare them _global or use timeline variables. How do I do this? Do I have to create and pass an object datatype with the various variables in it?

Can you declare your own constants in AS 2.0? Flash seems to have in built constants like Math.PI...but no way to declare yr own?

0
ashugarg00
Asked:
ashugarg00
1 Solution
 
negatyveCommented:
That's what normally happen, variables are passed by value when are of simple data type, and by reference when of complex:

// simple data type
var a:Number = 3;
function changeValue(param:Number):Void
{
      param = 4;      
}
trace(a);
changeValue(a);
trace(a);

// complex data type
var b:Array = [1, 2, 3];
function addValue(param:Array):Void
{
      param.push(4);
}
trace(b);
addValue(b);
trace(b);

>Can you declare your own constants in AS 2.0?

Surely, you can. You should create a static dynamic Class, and assign it your "global variables":


dynamic class Repository
{
      static public var yourVar:datatype = value;
      static public function yourMethod(params:datatype):returnType
      {
            
      }
}

and then

Repository.yourglobalvariable = yourvalue;
0
 
ashugarg00Author Commented:
Thanks Neg!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now