# Updating a variable before it is used

**URL:** https://forum.kirupa.com/t/updating-a-variable-before-it-is-used/63243
**Category:** Uncategorized
**Created:** [September 4, 2004, 7:39am UTC](https://forum.kirupa.com/t/updating-a-variable-before-it-is-used/63243 "2004-09-04T07:39:55Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![balthazar](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@balthazar](https://forum.kirupa.com/u/balthazar)
#### Post date: [September 4, 2004, 7:39am UTC](https://forum.kirupa.com/t/updating-a-variable-before-it-is-used/63243/1 "2004-09-04T07:39:55Z")

</div>

dear experts help me become more like you!

Things have become a lot clearer for me since my last post so i hope this second attempt will make it easier for u to answer:  
I have a ‘next’ button for a slideshow which i want to do the following:

on(press) {  
\_root.Number=\_root.Number+1;  
content.loadMovie(\_root.Url);  
}  
where my variables have been defined in a Frame as:  
var Url = ‘Pictures/photo’+Number+’.jpg’  
var Number= 1;

The reason i have used the variable Number in my Url variable and not directly in the loadMovie target (which does work) is that i want to be able to sometimes change the variable Url. Eg. when a user clicks on a series button such as ‘Cities’ i could get the next button to cycle through the first picture in each series in my array serie[]:  
\_root.url = ‘Pictures/serie[Number]’+photo1.jpg

the problem remains that my next button continues to use the old value for number so i get the same image over and over again.  
Anybody have any ideas??

thanxs a lot in advance!

---

<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: [September 4, 2004, 8:19am UTC](https://forum.kirupa.com/t/updating-a-variable-before-it-is-used/63243/2 "2004-09-04T08:19:59Z")

</div>

[AS]  
on(press)  
{  
\_root.Number = \_root.Number + 1;  
var newURL = ‘Pictures/photo’ + \_root.Number + ‘.jpg’;  
content.loadMovie(newURL);  
}  
[/AS]

you need to make a new string each time.

---

<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: [September 4, 2004, 8:27am UTC](https://forum.kirupa.com/t/updating-a-variable-before-it-is-used/63243/3 "2004-09-04T08:27:22Z")

</div>

does that mean i can change the var newUrl inside the on(press) handler? if so how?

---

<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: [September 4, 2004, 9:03am UTC](https://forum.kirupa.com/t/updating-a-variable-before-it-is-used/63243/4 "2004-09-04T09:03:31Z")

</div>

in the above case, everytime you press “it” \_root.Number will increase by one and you will then load the respective URL. i.e. if you keeping pressing “it” you will load:

‘Pictures/photo2.jpg’

‘Pictures/photo3.jpg’

‘Pictures/photo4.jpg’

‘Pictures/photo5.jpg’

…

---

<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: [September 4, 2004, 10:44am UTC](https://forum.kirupa.com/t/updating-a-variable-before-it-is-used/63243/5 "2004-09-04T10:44:36Z")

</div>

Yes, i know, my question was how can i use the same button to also use

Url = ‘Pictures/serie[Number]’+photo1.jpg

im pretty sure u cant change a variable inside a function so how do i set it up so that i can change var url from the outside when needed.

ill repeat that the reason i want to be able to do this is that my next button has to cycle through images in a folder (photo1,photo2…) and also when the user clicks a series button cycle through only the first image of each folder (see above and previous message).

im sorry i wasnt clear enough the first time, can u give it one more shot?

or anybody? im going crazy! balthazar

---

<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: [September 4, 2004, 2:56pm UTC](https://forum.kirupa.com/t/updating-a-variable-before-it-is-used/63243/6 "2004-09-04T14:56:47Z")

</div>

balthazar, please do not post the same question in more than one forum.
