-
Question about variable names...
Hi
Can anyone help me with this..
PHP Code:
textNumber = 0; text0 = "Sentance one"; text1 = "Sentance two"; text2 = "Sentance three"; textX = text[+textNumber].toUpperCase();
I know the above text[+textNumber] wont work but what do i write instead of [+textNumber] to make it work
so everytime textNumber changes from 0 to 1 etc.. the variable textX will update to the correct one.
So if textNumber was 1 then textX would update to text1 and make it upper case like:
PHP Code:
textX = text1.toUpperCase();
hope this makes sense.
thanks.
Last edited by mexicanbean; 09-14-2010 at 02:11 PM.
-
[Horse Thief]
Well, there are a few problems with your above code. In the textX line, Flash is likely thinking that "text" is an Array or an Object. It's not the proper syntax for converting a String to a Variable name.
I believe you might have better luck employing a different method. In the code below, I'm setting an Array with your sentences in it. I then use "textNumber" to reference a position in that Array. You can paste this code into a new FLA & change "textNumber" to any number which is one less than the total amount of items in the Array. This Array has 3 items in it, so you can use the Numerals 0, 1, or 2. Arrays start at index Zero, so Zero references the first position in the Array, or 'Sentence one'. This method will likely be more flexible because you won't have to create a whole new Variable for each sentence - just dump them all into the Array.
Code:
var textNumber:uint = 0;
var textArray:Array = new Array('Sentence one','Sentence two','Sentence three');
var textX:String = textArray[textNumber].toUpperCase();
trace(textX);
1 Infinite Loop, Cupertino is a portal of Hell.
-
for(var i:Number = 0; i< 3; i++){
_root["textX" + i] = _root["text" + i].toUpperCase();
}
contains:
text1;2;3
textX1;2;3
-
Thanks guys, i ended up using the array method, i completely forgot i could do it as an array, but thanks koenahn for your loop method, i wrote it for future reference
-
[Horse Thief]
Rawk
1 Infinite Loop, Cupertino is a portal of Hell.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|