# Passing additional arguments to function

**URL:** <https://forum.kirupa.com/t/passing-additional-arguments-to-function/260841>\
**Category:** flash\
**Created:** [May 20, 2008, 1:43pm UTC](https://forum.kirupa.com/t/passing-additional-arguments-to-function/260841 "2008-05-20T13:43:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wyktor](https://avatars.discourse-cdn.com/v4/letter/w/ed8c4c/32.png) [@wyktor](https://forum.kirupa.com/u/wyktor)\
**Post date:** [May 20, 2008, 1:43pm UTC](https://forum.kirupa.com/t/passing-additional-arguments-to-function/260841/1 "2008-05-20T13:43:17Z")

</div>

Hi, I have small syntax issue

I have four NetStream objects that receive cuepoints from different videos. I’d like to define one function for them all instead of using four inline functions and I’m stuck with syntax  
Here’s the code:

```auto
 
ns1.onCuePoint = callCuePoint;
ns2.onCuePoint = callCuePoint;
ns3.onCuePoint = callCuePoint;
ns4.onCuePoint = callCuePoint;
 
function callCuePoint(infoObject:Object):void {
   trace(infoObject)
}

```

This works fine, but what if I want to pass additional parameter (ID) to callCuePoint function?

I tried calling it using:

```auto
ns1.onCuePoint = callCuePoint("video1")

```

Which works, but obviously I loose the infoObject. Can anyone help me with this. How can I call the callCuePoint function with both - InfoObject and ID

thanks for help

---

<div class="post-metadata">

**Author:** ![Pier25](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pier25](https://forum.kirupa.com/u/Pier25)\
**Post date:** [May 20, 2008, 1:52pm UTC](https://forum.kirupa.com/t/passing-additional-arguments-to-function/260841/2 "2008-05-20T13:52:29Z")

</div>

you can do it in many ways…

Pass different variables for each argument

function myfunction(arg1,arg2,arg3){  
trace(arg1+" “+arg2+” "+arg3);  
}

myfunction(“hello”,“my name is”,“pier”);

Pass an object:

function myfunction(args\_object){  
trace(args\_object.name); //gives Pier  
}

my\_object.name = “Pier”

myfunction(my\_object);

Or pass an array

cars\_array[0] = “Ford”

function myfunction(array){  
trace(array[0]); //that gives ford  
}

myfunction(my\_array);

Hell I think you can even pass a function…

---

<div class="post-metadata">

**Author:** ![wyktor](https://avatars.discourse-cdn.com/v4/letter/w/ed8c4c/32.png) [@wyktor](https://forum.kirupa.com/u/wyktor)\
**Post date:** [May 20, 2008, 4:55pm UTC](https://forum.kirupa.com/t/passing-additional-arguments-to-function/260841/3 "2008-05-20T16:55:56Z")

</div>

I know all of these, but perhaps I didn’t explain my problem correctly.  
The onCuePoint event handler requires one parameter which is called infoObject. My question is, how can I pass another parameter to the onCuePoint event handler. As soon as I call it using any of the methods described above, I loose the infoObject object which I need to successfuly process the video.

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [May 20, 2008, 6:34pm UTC](https://forum.kirupa.com/t/passing-additional-arguments-to-function/260841/4 "2008-05-20T18:34:21Z")

</div>

Have you thought about using the built-in arguments array with your function?

arguments  
Object  
|  
±arguments

public class arguments  
extends Object

An arguments object is used to store and access a function’s arguments. While inside the function’s body it can be accessed with the local arguments variable.

The arguments are stored as array elements, the first is accessed as arguments[0], the second as arguments[1], etc. The arguments.length property indicates the number of arguments passed to the function. Note that there may be a different number of arguments passed in than the function declares.

Availability: ActionScript 1.0; Flash Player 5 - As of Flash Player 6 the arguments object supports all methods and properties of the Array class.

Check out “arguments” in the Help files.

---

<div class="post-metadata">

**Author:** ![wyktor](https://avatars.discourse-cdn.com/v4/letter/w/ed8c4c/32.png) [@wyktor](https://forum.kirupa.com/u/wyktor)\
**Post date:** [May 20, 2008, 9:22pm UTC](https://forum.kirupa.com/t/passing-additional-arguments-to-function/260841/5 "2008-05-20T21:22:48Z")

</div>

That’s great idea, I totally forgot that arguments can be addresed through this class.  
Anyways I temporarily solved this by adding new property to NetStream which I can check from my generic function with this keyword

Thanks for help:)
