# Can variables be used as function argument?

**URL:** <https://forum.kirupa.com/t/can-variables-be-used-as-function-argument/317740>\
**Category:** Uncategorized\
**Created:** [December 31, 2010, 10:07pm UTC](https://forum.kirupa.com/t/can-variables-be-used-as-function-argument/317740 "2010-12-31T22:07:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhnh](https://avatars.discourse-cdn.com/v4/letter/b/eb8c5e/32.png) [@bhnh](https://forum.kirupa.com/u/bhnh)\
**Post date:** [December 31, 2010, 10:07pm UTC](https://forum.kirupa.com/t/can-variables-be-used-as-function-argument/317740/1 "2010-12-31T22:07:26Z")

</div>

OK, I have an extended MovieClip class that has 10 Boolean properties. There are 6 instances of the clip on the stage. Any of the properties of each instance can be set independent of the same property in other instances, so…

```auto

clip1.foo = true;
clip2.foo = false;
//etc.

```

There are points in the timeline when I need a particular property in all of the instances to be the same. I set up a function…

```auto

function all(val):void{
 for(var j:int=0;j<6;j++){
  this["clip"+j].foo = val;
  trace("clip"+j+" foo = "+this["clip"+j].foo);
 }
}
 
all(true);

```

… which works, but only for the Boolean property [COLOR=red]foo[/COLOR]. I’d like to add different properties as an additional argument. I tried this…

```auto

function all(p,val):void{
 for(var j:int=1;j<4;j++){
  this["clip"+j].p = val;
  trace("clip"+j+" foo = "+this["clip"+j].foo);
 }
}
 
all(foo,true);

```

… which does NOT work. I’d like to be able to drop in any of the properties and a value into a single function, rather than having to concoct a function for each of the 10 properties. Is there a way to do this?

Many thanks in advance!
