# Defining variables in a function

**URL:** <https://forum.kirupa.com/t/defining-variables-in-a-function/145112>\
**Category:** Uncategorized\
**Created:** [April 19, 2005, 11:42pm UTC](https://forum.kirupa.com/t/defining-variables-in-a-function/145112 "2005-04-19T23:42:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jedhu0920](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jedhu0920/32/905_2.png) [@jedhu0920](https://forum.kirupa.com/u/jedhu0920)\
**Post date:** [April 19, 2005, 11:42pm UTC](https://forum.kirupa.com/t/defining-variables-in-a-function/145112/1 "2005-04-19T23:42:35Z")

</div>

Is it possible to define a variable inside of function where the actual variable name will change based on what parameters the function is called with? Take a look at this code:

```auto

//define the function
function attachVid(nc, ns, curVid, vidFile) {
//I want the nc on the left side of this variable assignment to change to "video1", the name coming from the command calling the funtion
    var nc = new NetConnection();
    nc.connect(null);
//I want the ns on the left side of this variable assignment to change to "videoStream1", the name coming from the command calling the funtion
    var ns = new NetStream(nc);
//The curVid part of the will be replaced with _root.my_mc1 (instance name of an embedded video object sitting on the stage), the name coming from the command calling the function
    curVid.attachVideo(ns);
    ns.connect();
    //the vidFile part of this snippet is changed to "millersgap_med001.flv", the FLV name coming from the function call
    ns.play(vidFile);
}

//call the function
attachVid("video1", "videoStream1", _root.my_mc1, "millersgap_med001.flv");

```

I am trying to make the net Connection and net Stream object unique each time the function is called because I am trying to play like 5 flv’s on stage simultaneously. As far as I know, each video stream needs a unique net Connection and a unique net Stream object. But it doesn’t seem to be working. Does anyone see any problems with my code?
