problems with txt files inside flash
I am creating a game, and am using txt files to help load different information.
This code is for a charecter selection screen. On one side I have three races: Troll, Halfling, and Human. Each has thier own button. On the other side of the form there are three races: Beastlord, Druid, and Paladin, again each one is a seperate button. In the middle I have 8 variables with names such as STR, ENR AGI etc...each one has a name and then a text box. I am using the txt files to set the values for what goes in each of the variable boxes. The first set is loading fine, but I want it so that you can click on a race and it brings the stats up, and then you click on a class and it adds to those stats, increasing SOME of the numbers...(whichever I defined in the txt file to do) this is where I am having problems. It seems to me that flash is treating my txt file as a string and so when I ask it to add to those values it does not do it.
Here is what the txt file looks like for the Race buttons...
I then put it in flash with this code...
raceChoice = "troll.txt";
This all works fine.
My class txt file looks like this...
and is loaded into the flash document with this code...
classChoice = "Druid.txt";
Ok so can anyone tell me why they think that it is not treating this as a variable and adding the two numbers together? The best I have gotten it to do is have the two numbers that i assigned go next to eachother but it would not add them.
Hope someone can help. Thank you
Yes everything you load from a text file in Flash is a string (just text). If you want to treat some of it as numbers you need to convert them yourself with either the method Number or parseInt (if you know you are converting integers). Check your actionscript dictionnary for more detail on both methods.
n1 = "15.5"; n2 = "20"; trace(n1+n2); // output: 15.520 n1 = Number(n1); n2 = parseInt(n2); trace(n1+n2); // output: 35.5
PS: Number also works for integer but parseInt doesn't work for decimals (it drops the decimal part)
|Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)|
|Thread||Thread Starter||Forum||Replies||Last Post|
|Flash Website Problems||mrdamon||Newbies||0||01-19-2009 06:18 PM|
|Flash FLV player Embed problems||emarie||Flash CS3 / Flash 9||1||06-28-2008 04:44 AM|
|How do I get MXP files into my flash document||chadulus||Newbies||3||03-17-2006 04:59 PM|
|Software for translating Flash files into foreign languages||avral||New Softwares||0||11-22-2002 04:56 AM|