# \[AS 2.0\] Accessing variable in parent function?

**URL:** <https://forum.kirupa.com/t/as-2-0-accessing-variable-in-parent-function/250530>\
**Category:** flash\
**Created:** [January 30, 2008, 10:47am UTC](https://forum.kirupa.com/t/as-2-0-accessing-variable-in-parent-function/250530 "2008-01-30T10:47:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lixus](https://avatars.discourse-cdn.com/v4/letter/l/9fc348/32.png) [@lixus](https://forum.kirupa.com/u/lixus)\
**Post date:** [January 30, 2008, 10:47am UTC](https://forum.kirupa.com/t/as-2-0-accessing-variable-in-parent-function/250530/1 "2008-01-30T10:47:19Z")

</div>

I’m new to this forum, so, “Hello World”! 🙂

I’m also relatively new to programming with actionscript, so my code might look quite messy to you 😉

Here is my function. It loads the contents of an .xml file and creates a playlist for a video player.  
Now my problem is that i want to set the “onRelease” function dynamicaly for each playlist item. but inside the onRelease-function i cannot access the variable i. do you have a hint / workaround for me???

here is my (shortened for readability) code

```auto

    vlist.onLoad = function() {
        
        
        for (i=0; i<_root.videoList.length; i++) {
    
            _root.playlist.attachMovie ("listenitem","listitem" + i, _root.playlist.getNextHighestDepth());
            _root.playlist["listitem"+i]._x = 0;
            _root.playlist["listitem"+i]._y = 18 + i * 18;
                
            _root.playlist["listitem"+i].listlabel.text = _root.videoList*['title'];
                
            _root.playlist["listitem"+i].onRelease = function() {

                // I want to access the variable i in here, but this does not work... :*(
                _root.FLVmovie.load (_root.contentVidPath + _root.videoList*['file']);
                trace("LADE: " + _root.contentVidPath + _root.videoList*['file']);
                playVid(); 
            }
        
        }
    
    }
    vlist.load(_root.contentVid);

```

Thank you in advance

lixus
