# \[AS2\] Add 1 to a variable outside a function from within

**URL:** <https://forum.kirupa.com/t/as2-add-1-to-a-variable-outside-a-function-from-within/277259>\
**Category:** flash\
**Created:** [December 10, 2008, 12:43am UTC](https://forum.kirupa.com/t/as2-add-1-to-a-variable-outside-a-function-from-within/277259 "2008-12-10T00:43:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![xstevey\_bx](https://avatars.discourse-cdn.com/v4/letter/x/91b2a8/32.png) [@xstevey\_bx](https://forum.kirupa.com/u/xstevey_bx)\
**Post date:** [December 10, 2008, 12:43am UTC](https://forum.kirupa.com/t/as2-add-1-to-a-variable-outside-a-function-from-within/277259/1 "2008-12-10T00:43:28Z")

</div>

I want to import a new image ever 5 seconds but how can I incriment the counter variable from within the function?

```php
count=0;
function loadimage(count) {
	trace(count);
           count++;
	loadMovie("images/"+q+"/"+a+"/"+count+".jpg", mc_slideshow);
}

loadMovie("images/"+q+"/"+a+"/"+count+".jpg", mc_slideshow);

intervalID = setInterval(loadimage, 5000, count);

```

Thanks
