all groups > flash actionscript > april 2006 >
You're in the

flash actionscript

group:

Conditional statement variable change


Conditional statement variable change jondro
4/28/2006 9:59:30 PM
flash actionscript: I want a button called "next_btn" to change a variable called "pres" to
whatever variable is next in the sequence. So on the first click it will change
pres=vice and then the second time it is clicked it will change it to
pres=vice2 and the third time pres=sec and the fourth pres=trea.

I am sure there are many ways to do this. My first thought was an if statement
where if(pres=vice) {pres=vice2;} and so on. An easier way would be a switch
statement but I am not sure of the syntax. Another way would be to change the
variables to numbers and do a loop so that every time the next button is
clicked it adds 1 or something but again I am not sure how to write this out.
Please help...this is what I have so far:

loadVariablesNum("bio.txt", 0);
var pres = new Array(vice, vice2, sec, trea);
var n = 0;
var presn;
next_btn.onRelease = function() {
nextImage();
presn = pres;
n++;
if (n == pres.length) {
n = 0;
}
trace(presn);
};

In the bio.txt document it has the following:
&presn=blah
&vice= blah2
etc.

The dynamic text box variable is set to "presn" and when first loaded it
displays the blah but when you click the button blah2 does not appear. Instead
it says undefined.
Re: Conditional statement variable change jondro
4/28/2006 10:37:53 PM
the nextImage() code is a seperate function that changes a picture but it
doesnt effect the rest of the code...if it helps I have a different approach
that is less complicated and almost works but not completely...here it goes:

I have a dynamic textbox with the var set to "pres"

loadVariablesNum("bio.txt", 0);
n=1;
next_btn.onRelease = function() {
nextImage();
pres="pres"+n;
n++;
trace(pres);
};

In the bio.txt file there are the following variables:

&pres=something
&pres1=something else
&pres2=etc.

When it loads the dynamic textbox displays "something" but instead of
displaying the "something else" when i click the button it displays "pres1"
Why won't "something else" come up when I click the button???
Re: Conditional statement variable change jondro
4/29/2006 4:45:46 AM
AddThis Social Bookmark Button