|
-
Actionscript Developer
Converting a string to a variable
I have a problem,
I'm making this message cycling headline popup thingy.
This is my code for one of the frames:
Let's say that i declared a variable "headline1 = "Hello Everybody!"
on one frame. I have a counter called "hnews" as well that starts at 0 and goes to a limit.
the next frame i have
PHP Code:
var x = "headline"+_root.hnews
scroller.thenews = x;
I want the scroller to be equal to the variable headline1, not the string headline1. I've tried hundreds of things like brackets and curly braces, but all in vain.
Plz help,
Danny
K2xL - My games, tutorials, message boards, and experiments.
Blog
-
Trycode: var x = eval("headline" + _root.hnews);
-
Actionscript Developer
Sweet, thanks,
but i have another question now...
I tried making an array and a for loop to load variables from a txt file.
PHP Code:
loadText = new loadVars();
loadText.load("Variables.php");
loadText.onLoad = function(success) {
if (success) {
headlinecount = this.headlinecount; //total number of headlines
headline = new Array(headlinecount);
for (a=0; a<headlinecount; a++) {
headline[a] = this.headline[a]); // < - here is problem
}
In my file,
i have
&headline1=Yo
&headline2=Yo
&headline3=Yo
&headline4=Yo
So headlinecount should be 4.
It don't work. How can I get the index of the array?
Thanks!
K2xL - My games, tutorials, message boards, and experiments.
Blog
-
In your file, did you use ' and ; ?
&headline1 = 'Yo';
&headline2 ..... etc.
-
Actionscript Developer
No, and i don't think i need to...
K2xL - My games, tutorials, message boards, and experiments.
Blog
-
Use a for in loop to pull out all the data from the textfield then you won't need to know how many exists in the file. If you need to use the value later, increment a counter in the for in loop and reference to that.
I'd personally use XML for this, then you can use childNodes.length to specify the for loop's properties, but I like whoring XML everywhere I go. It's worth looking up though to replace usage of textfiles...
-
Actionscript Developer
Yeah, the for loop though has a constraint, see the file says how many variables the for loop should extract.
K2xL - My games, tutorials, message boards, and experiments.
Blog
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
|