# \[AS1/2\] passing an object as a variable in a function

**URL:** https://forum.kirupa.com/t/as1-2-passing-an-object-as-a-variable-in-a-function/109435
**Category:** Uncategorized
**Created:** [May 5, 2004, 3:23pm UTC](https://forum.kirupa.com/t/as1-2-passing-an-object-as-a-variable-in-a-function/109435 "2004-05-05T15:23:01Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![m00g](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@m00g](https://forum.kirupa.com/u/m00g)
#### Post date: [May 5, 2004, 3:23pm UTC](https://forum.kirupa.com/t/as1-2-passing-an-object-as-a-variable-in-a-function/109435/1 "2004-05-05T15:23:01Z")

</div>

I have a movieClip prototype that calls another function once it has finished.  
The other function could be one of many.  
I want to be able to pass the variables of the second function to the first function:

```auto
MovieClip.prototype.func1=function(varA,varB,func2name,func2args){
// do something
// once done call second function:
this[func2Name](func2args.join(','));
};

```

// called using:

```auto
myMC.func1(varA,varB,"func2Name",{func2Arg1:value, func2Arg2:value})

```

Any idea how this should be written?  
At the moment only the first variable of func2 is populated…

Thanks for helpin me out on this 1 🙂

Ed

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 5, 2004, 4:07pm UTC](https://forum.kirupa.com/t/as1-2-passing-an-object-as-a-variable-in-a-function/109435/2 "2004-05-05T16:07:09Z")

</div>

Ah, for that you use function.apply:

```auto

  MovieClip.prototype.someFunc = function(varA,varB,finishFunc,finishObj,finishParams){
  // do some stuff...
  finishFunc.apply(finishObj,finishParams);
  }
  MovieClip.prototype.funcToCall = function(msg){
  trace(msg);
  }
  this.someFunc(a,b,MovieClip.prototype.funcToCall,_root,["hello there"]);
  

```

That will execute MovieClip.prototype.funcToCall ‘on’ \_root, so basically \_root.funcToCall (funcToCall was declared in the MovieClip prototype).

\*For some reason it keeps inserting that space in finishParams, remove it.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 5, 2004, 4:45pm UTC](https://forum.kirupa.com/t/as1-2-passing-an-object-as-a-variable-in-a-function/109435/3 "2004-05-05T16:45:40Z")

</div>

Thanx Voetsjoeba - you are a star - been tearin my hair out for days now - gonna need some regain!  
Thanks again,  
Ed

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 5, 2004, 4:52pm UTC](https://forum.kirupa.com/t/as1-2-passing-an-object-as-a-variable-in-a-function/109435/4 "2004-05-05T16:52:05Z")

</div>

You’re welcome, m00g 🙂
