Parameter Passing

I’m not totally sure about this but from what I understand of AS, if you pass a variable it passes it as a reference parameter. Can you pass it as a value parameter or no?

I don’t understand what you mean.

when you pass an object as a parameter, there are 2 ways it can be passed. It can either copy the value and that value will exist within the function (value passing) or it can pass a reference to the location of the object (reference passing). For example, in this function:
[AS]
dog = function(a){
a = 5;
}

cat = function(){
var b = 6;
dog(b);
[/AS]

if it is a value parameter, b will trace 6 afterwards. If it is reference, it will trace 5. See sorta what I mean?

Well I am not really understanding because “a” is an argument of your function, not a variable, so it is conflicting.

Of course you can however make it an object oriented variable like “this.a”

Perhaps this can help you:
http://www.kirupa.com/developer/actionscript/tricks/scope.htm

Here is an example of being able to use “a” as a variable in the function and “a” as an argument in the function. Still seems a bit inefficient to me though…

[AS]dog = function (a) {
var a = 5;
trace("var a = "+a);
trace("argument a = "+arguments[0]);
};
cat = function () {
var b = 6;
dog(b);
};
dog(2);
cat();[/AS]

Ok I will try and explain again. A value parameter means only the value of the variable is passed. If you pass a number to a function using a value parameter, you can change it as much as you want but the original value will remain the same outside that function. It is only within that function that it takes on a different value. A copy of the variable is sent as opposed to the actual variable itself. In a reference parameter, the actual object location in memory is passed and if you change the object there, it changes everywhere. Flash, from what I have seen, uses reference parameters. The point of value parameters is to allow a variable to be changed and modified only within the scope of that function.

Ohhh, alright I gotcha! Sorry for being a dolt.

I don’t believe you can pass it as a value parameter, but if there were anyone to ask about something like that it would be Senocular (I swear he built flash himself)

I know. Maybe he is a Macromedia representative in disguise.