# Simpel: variable within variable

**URL:** <https://forum.kirupa.com/t/simpel-variable-within-variable/63203>\
**Category:** Uncategorized\
**Created:** [September 3, 2004, 9:16pm UTC](https://forum.kirupa.com/t/simpel-variable-within-variable/63203 "2004-09-03T21:16:41Z")\
**Posts on this page:** 14\
**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 3, 2004, 9:16pm UTC](https://forum.kirupa.com/t/simpel-variable-within-variable/63203/1 "2004-09-03T21:16:41Z")

</div>

hello generous flash experts,  
please help me get some sleep again…  
ive got two variables in \_root:  
var number = 1;  
var url= ‘Pictures/Rotterdam/photo’+number;  
buttons in my main movie change the values of these variables.  
my next button looks like this:  
on(press) {  
number = number +1;  
loadMovie(url);}  
Problem:  
loadMovie loads photo1 and thus has not used the new value for my number variable.  
how do i write my url variable so that it has the new value?

---

<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 3, 2004, 9:28pm UTC](https://forum.kirupa.com/t/simpel-variable-within-variable/63203/2 "2004-09-03T21:28:09Z")

</div>

on frame:

```auto

var count;
var url = 'home'+count+".swf";

```

on button:

```auto

on (press) {
_root.count = 2;
_root.loadMovie(url);
}

```

just substitute the default url for whatever you need the dynamic address to be. there was no need for you to assign a value to the count and simply increment it. just bring it to being and change it as necessary through your buttons.

also, its a root variable so it is probably best to address it as such. although you don’t have to because it will work either way, doing so can avoid possible problems.

---

<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 3, 2004, 9:41pm UTC](https://forum.kirupa.com/t/simpel-variable-within-variable/63203/3 "2004-09-03T21:41:25Z")

</div>

hey,

thanx for the quick respons.  
i do need to increment the count because its a sort of slide show. So everytime u click on next the number of the slide needs to increase.  
also the url needs to change because there are different series.

maybe im missing something completely obvious to flash experts but i think this is the only way. Any other ideas?

Balthazar

> [@maximum\_flash](#):
>
> on frame:
> 
> ```auto
> 
> var count;
> var url = 'home'+count+".swf";
> 
> ```
> 
> on button:
> 
> ```auto
> 
> on (press) {
> _root.count = 2;
> _root.loadMovie(url);
> }
> 
> ```
> 
> just substitute the default url for whatever you need the dynamic address to be. there was no need for you to assign a value to the count and simply increment it. just bring it to being and change it as necessary through your buttons.
> 
> also, its a root variable so it is probably best to address it as such. although you don’t have to because it will work either way, doing so can avoid possible problems.

---

<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 3, 2004, 10:07pm UTC](https://forum.kirupa.com/t/simpel-variable-within-variable/63203/4 "2004-09-03T22:07:04Z")

</div>

dont know if this is how you want to do it, but i did it with a function.

on the frame:

```auto

//changeMovie function()
function changeMovie(operand) {
count += operand;
var url = 'home'+count+'.swf';
_root.pic.loadMovie(url);
}
//display 1st image
changeMovie(1);

```

on the button:

```auto

//call the changeMovie function
on (press) {
changeMovie(1);
}

```

the number will be automatically incremented one by the changeMovie function. changing 1 to 2, 2 to 3… you get the idea. that is just how i would do it. it makes things more easy and portable.

---

<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 3, 2004, 10:11pm UTC](https://forum.kirupa.com/t/simpel-variable-within-variable/63203/5 "2004-09-03T22:11:13Z")

</div>

as for a back button, you could just make another function that will make it go back 1 number.

```auto

//call the changeMovie function, passing a -1 parameter to go back 
on (press) {
changeMovie(-1);
}

```

---

<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 3, 2004, 10:20pm UTC](https://forum.kirupa.com/t/simpel-variable-within-variable/63203/6 "2004-09-03T22:20:30Z")

</div>

maybe i shoudnt have started this thread with simple…

My slideshow is part of a viewer which loads in external pictures in different folders.  
If i could get my next button to work the way i have it set up it would mean i could use it for multiple functions. For example i could also set my url to be just the first picture in each folder and not increment the number each time. Ive tried many other set ups but none would be simpler on whole than how i have it now.

ive attached a quick test.fla which is what i need to work. please give it one more shot 😕 ?

---

<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 3, 2004, 10:22pm UTC](https://forum.kirupa.com/t/simpel-variable-within-variable/63203/7 "2004-09-03T22:22:44Z")

</div>

hey forgot to put in the number+1 part

---

<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 3, 2004, 10:23pm UTC](https://forum.kirupa.com/t/simpel-variable-within-variable/63203/8 "2004-09-03T22:23:42Z")

</div>

wouldn’t open…

you should have said all this when you asked your question.

---

<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 3, 2004, 10:40pm UTC](https://forum.kirupa.com/t/simpel-variable-within-variable/63203/9 "2004-09-03T22:40:41Z")

</div>

is this possible?

var number = 1;  
var url = ‘Pictures/photo’+number+’.jpg’;

on(press) {  
number= number+1;  
content.loadMovie(url);  
trace (url);}

ouput: ‘Pictures/photo2.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 3, 2004, 10:43pm UTC](https://forum.kirupa.com/t/simpel-variable-within-variable/63203/10 "2004-09-03T22:43:02Z")

</div>

no, it isn’t. when you use the var keyword, you are making a local variable (which can really only be used in **functions**.)

---

<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 3, 2004, 10:52pm UTC](https://forum.kirupa.com/t/simpel-variable-within-variable/63203/11 "2004-09-03T22:52:50Z")

</div>

why does it load the first picture then? it seems to read the variables correctly but only in the wrong order.

is \_global.variables an option?

Balthazar

ps i have to let u know i really apreciate this…

---

<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 3, 2004, 10:56pm UTC](https://forum.kirupa.com/t/simpel-variable-within-variable/63203/12 "2004-09-03T22:56:43Z")

</div>

on frame:

```auto

var count = 1;

```

on button:

```auto

on (release) {
count++;
_root.pic.loadMovie("home"+count+".swf");
}
 

```

where pic is just a container i made to hold the loaded movie.

simpler, does the same thing you want and is more efficient.

it’s no problem, i just wish i could get this fixed…

---

<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 3, 2004, 11:10pm UTC](https://forum.kirupa.com/t/simpel-variable-within-variable/63203/13 "2004-09-03T23:10:43Z")

</div>

my its because im sleepy (its past 1 in the morning here)…

I know the way u have it is simpler, i had like that before. The reason i want it my way is because it makes other functions ten times easier and simpler.

i understand if u give up this point. I think im going to sleep, if u have a sollution which somehow keeps the setup for var url, i will be delighted to read it in the morning!

Balthazar

> [@maximum\_flash](#):
>
> on frame:
> 
> ```auto
> 
> var count = 1;
> 
> ```
> 
> on button:
> 
> ```auto
> 
> on (release) {
> count++;
> _root.pic.loadMovie("home"+count+".swf");
> }
> 
> ```
> 
> where pic is just a container i made to hold the loaded movie.
> 
> simpler, does the same thing you want and is more efficient.
> 
> it’s no problem, i just wish i could get this fixed…

---

<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 3, 2004, 11:13pm UTC](https://forum.kirupa.com/t/simpel-variable-within-variable/63203/14 "2004-09-03T23:13:01Z")

</div>

its 6:11 pm
