# Setting variable - help please

**URL:** <https://forum.kirupa.com/t/setting-variable-help-please/25489>\
**Category:** Uncategorized\
**Created:** [July 13, 2003, 3:06pm UTC](https://forum.kirupa.com/t/setting-variable-help-please/25489 "2003-07-13T15:06:41Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![w\_digital](https://avatars.discourse-cdn.com/v4/letter/w/35a633/32.png) [@w\_digital](https://forum.kirupa.com/u/w_digital)\
**Post date:** [July 13, 2003, 3:06pm UTC](https://forum.kirupa.com/t/setting-variable-help-please/25489/1 "2003-07-13T15:06:41Z")

</div>

I have applied the following code to a button:

on (press, release, keyPress “\<Down\>”) {  
gallerycount = gallerycount+1;  
if (gallerycount\<2) {  
gallery = gallery1;  
} else {  
gallery = gallery2;  
}  
}

the variable “Gallery” is a dybamic text field variable. The code loads diffrent text from txt file based on key presses. For some reason (maybe I’m being stupid) the code loads the text then instantly disappears?

Any ideas? more info?

thanks in advance guys!!

---

<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:** [July 13, 2003, 3:20pm UTC](https://forum.kirupa.com/t/setting-variable-help-please/25489/2 "2003-07-13T15:20:36Z")

</div>

I didnt understand what exactly you are tring to do.  
Are you loading an external txt file? Which event changes the textfield content? Which vars are on the external txt?  
:-\

---

<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:** [July 13, 2003, 4:52pm UTC](https://forum.kirupa.com/t/setting-variable-help-please/25489/3 "2003-07-13T16:52:02Z")

</div>

Yeah sorry, I probably didn’t explain well.

Yeah, I’m loading an external text file.

The vars in text file is:

gallery 1 & gallery2.

I want to change the contents of textfield by the click of the button.

any ideas?

---

<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:** [July 13, 2003, 4:57pm UTC](https://forum.kirupa.com/t/setting-variable-help-please/25489/4 "2003-07-13T16:57:32Z")

</div>

Maybe this helps you.

---

<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:** [July 13, 2003, 5:28pm UTC](https://forum.kirupa.com/t/setting-variable-help-please/25489/5 "2003-07-13T17:28:28Z")

</div>

claudio thanks a lot mate!!

That helped me 120%

I got it working - I learnt some new conepts from that.

Thanks again.

---

<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:** [July 13, 2003, 5:31pm UTC](https://forum.kirupa.com/t/setting-variable-help-please/25489/6 "2003-07-13T17:31:58Z")

</div>

Glad I could help  
🙂

---

<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:** [July 13, 2003, 6:07pm UTC](https://forum.kirupa.com/t/setting-variable-help-please/25489/7 "2003-07-13T18:07:11Z")

</div>

claudio.

1 last thing: in your AS you done this:-

loadText[“text”+count]

cool.

can you do a simular thing to a variable assignment?

e.g. I want to set variable “gallery” to the contents of “gallery1”, “gallery2”, etc…

I did this:

```
    gallery = "gallery"+gallerycount;

```

what i get is the litteral string GALLERY2 rather than the contents of “gallery2”. whats the best way forward?

---

<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:** [July 13, 2003, 6:37pm UTC](https://forum.kirupa.com/t/setting-variable-help-please/25489/8 "2003-07-13T18:37:52Z")

</div>

Hmm again i am confused 😛 😛  
Maybe if you explain what you are trying to achieve… 🙂

---

<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:** [July 13, 2003, 6:48pm UTC](https://forum.kirupa.com/t/setting-variable-help-please/25489/9 "2003-07-13T18:48:07Z")

</div>

Ok…

I want to do what you have done in your fla, but slightly different.

When the button is pressed I want the variable “gallery” to equal the contents of “gallery1”, “gallery2”, etc. loaded from text file.

I have done this:-

gallerycount = 1;  
loadVariables(“data2.txt”, this);  
b1.onPress = function() {  
if (gallerycount != 1) {  
gallerycount–;  
gallery = “gallery”+gallerycount;  
}  
};  
b2.onPress = function() {  
if (gallerycount != max) {  
gallerycount++;  
gallery = “gallery”+count;  
}  
};

gallerycount, max, gallery1 and gallery2 all loaded from textfile.

when I press the button I get for example: gallery2  
as a string literal NOT the text in textfile…

is that clearer? let me know If u want more info?

any ideas?

---

<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:** [July 13, 2003, 7:00pm UTC](https://forum.kirupa.com/t/setting-variable-help-please/25489/10 "2003-07-13T19:00:30Z")

</div>

I have not tested this and dont know what you are trying to acomplish, but try this:[AS]max = 4;  
gallerycount = 1;  
loadText = new loadVars();  
loadText.load(“data2.txt”);  
loadText.onLoad = function(OK) {  
if (OK) {  
mytext.text = this[“gallery”+count];  
} else {  
trace(“Error”);  
}  
};  
b1.onPress = function() {  
if (gallerycount != 1) {  
gallerycount–;  
gallerycount = loadText[“gallery”+gallerycount];  
}  
};  
b2.onPress = function() {  
if (gallerycount != max) {  
gallerycount++;  
gallerycount = loadText[“gallery”+count];  
}  
};[/AS]

---

<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:** [July 13, 2003, 8:09pm UTC](https://forum.kirupa.com/t/setting-variable-help-please/25489/11 "2003-07-13T20:09:50Z")

</div>

I am trying to achieve exactly what you have done, but in a Flash 5 way.

I understand ‘loadVars’ is a Flash MX feature. I understand your code, and know it should work (apart from 1 thing), what I want to do is mimic this line (I have amended the line):

gallery = loadText[“gallery”+gallerycount];

…

in my code: gallery is my textfield variable. In the line above we set the variable gallery to “gallery”+count so if count = 2 gallery will = gallery2 right?

gallery2 is loaded from textfile and will now display gallery2’s text.

In my code I want to do this (lets say gallerycounter is 1):

1. press button
2. increment gallerycounter
3. now gallerycounter is 2
4. set gallery to the contents of the following:  
gallery1  
gallery2  
gallery3 etc…

to set gallery i’m doing this:

gallery = “gallery”+gallerycount

…it doesn’t work cause gallery now prints “gallery2” in words as apose to the CONTENTS of the variable gallery2.

so my question is, how do I pass the value instead of the words “gallery2”?

A big thanx if u can crack this 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:** [July 14, 2003, 5:32am UTC](https://forum.kirupa.com/t/setting-variable-help-please/25489/12 "2003-07-14T05:32:14Z")

</div>

Im a litttle bit confused, nut if you use the code i provided, it will load the variables in the txt file. :hangover:
