Accessing outside variables from functions

I can’t figure out how to access variables that are declared in a movie clip from a function declared in that same movie clip.

i.e.


var int1 = 1
var int2 = 2

function myfunction(){
int1++;
int2++;
}
myfunction();


I’m trying to do this in the main movie clip of a movie that I plan on importing dynamically in another movie. I’ve tried to use this.int1++, but I think that flash was looking for a variable that belongs to “myfunction” when I did that. I could just use _root.int1++ but like I said, I plan on dynamically loading this into another movie, in which case it would be pointing to the wrong movie.

Help!!

if i`m understanding this correctly, what you have written above will work as it is. You could declare the variables like
this.int1 =1

that is correct. those variables are declared in the scope of that script - the timeline script in whatever movieclip (beit _root or anyother) in which it was written. As such, it belongs to and is defined in that clip. myfunction being defined in that script actually has double access to those variables. 1) because it is defined in the same script as the variables and 2) because its defined in the same scope of those variables, that being the timeline. access via 1 is simply through the variables names as used above. access via 2 is through this.variablename. Both should work given the circumstance above.