Passing values ByRef, CONSTANTS in AS 2.0

Posted on 2005-04-26
Last Modified: 2010-04-03
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?

Question by:ashugarg00
    LVL 27

    Accepted Solution

    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;      

    // complex data type
    var b:Array = [1, 2, 3];
    function addValue(param:Array):Void

    >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;

    Author Comment

    Thanks Neg!

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
    I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
    The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
    The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now