|
-
Text Files - A Variable Question
Hey,
I promise this will be the last thread regarding text files for a while, and no this isnt regarding how you integrate them with Flash, because Ive learnt up to that point
But I've run into a little problem which is the last of many problems to complete this little assignment.
My question is, how do you use a variable in flash to tell flash which value to get from the text file. Normally you would say something like:
dynamicText.text = this.value1;
But what if you dont know which value is going to be chosen, so you use a variable instead like this:
code:
myData= new LoadVars();
myData.onLoad = function() {
whichStuff = "stuff3";
dynamicText.text = this.whichStuff // in other words 'this.stuff3'
};
myData.load("text files/dataText.txt");
The problem is, it returns an undefined value and so doesnt work. Does anyone have any input on this?
-
A serverside language like php and using GET or POST would do it justice, otherwise you just have to fetch all the data, split it yourself and choose the one you want
-
Hmm,
I thought I needed all the Php, but I suppose I need more. I was just really hoping there was a way to do something like:
Instead of this way [which works]
viewText.text = someText.somevariable2; - which takes a value from a text file
And do it this way [which doesnt]
viewText.text = someText[somevariable+number]; - number storing a value of 2
Hopefully that makes sense.
-
Try a simple test:
Have a .txt file called "vars.txt" next to (in the same folder as) your .swf.
In vars.txt, have this:
&var1=This is variable 1&
&var2=blah&
In the first frame of the _root of your flash file, put this:
Code:
stop();
loadVariables("vars.txt" , "");
onEnterFrame = function() {
if(input == undefined) {
disp = "";
}
else {
disp = _root["var"+input];
}
}
Then have an input text field with variable "input" and a dynamic text field with variable "disp". Test the movie. Try typing "1" and "2" into the input text field. Your 2 different .txt variables should appear.
Is that what you were looking for?
Last edited by BobJohnson; 03-24-2006 at 10:17 PM.
-
Senior Member
Use xml instead of textfiles and you have better control.
- The right of the People to create Flash movies shall not be infringed. -
-
Osteel,
I agree with cancerinform... Using text files for variables can be a real headache I would also suggest XML for this type of operation.
cheers,
Samuel Agesilas
http://www.levelofindustry.com
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
|