02-09-2011 08:24 PM
I have a general question and was wondering if someone can help me out. I am new to flash builder 4 so I would need very easy to understand answer. Here is my problem: I need to know how to save a text input value in one state and then call that value from a different state. Basically I am looking to have a text input box in states 1,2,3 and 4. Next I want to be able to call the values of those four text inputs so that I can add them and then display the total value in state 5. I have tried several different things and nothings works. I first tried to declare them as public and global variables and that didn't work. I also tried using them as a shared object but I feel like there is an easier way. I put together some code so you can see what I am looking to do. If anyone can lead me in the right direction it would be greatly appreciated.
Thanks in advance,
Brian
<fx
cript>
<![CDATA[
private function add():void{
var A:Number = Number(A.text);
var B:Number = Number(B.text);
var C:Number = Number(C.text);
var D:Number = Number(D.text);
var TotalScore:Number = A + B + C + D;
Total.text = TotalScore.toString();
}
]]>
</fx
cript>
Solved! Go to Solution.
02-09-2011 08:27 PM
hey,
i noticed your variable names for the numbers are the same as the ID's on your TextInputs. maybe that is causing a conflict. try changing your variable names so they arent the same and see if that changes things. good luck!
02-09-2011 08:28 PM
Try
Total.text = String( TotalScore );
Also, the "add" function is case sensitive. So the "click" callback should match.
02-09-2011 08:29 PM - edited 02-09-2011 08:30 PM
Ah, you're right JRab, getting confused wiht scope. Surprise the compiler did not warn him on that. Try using variables like "a_value", "b_value", etc.
02-09-2011 08:32 PM
I just put together that code so you can see what I am trying to do I understand all that you have said. My real code is all fine like you guys have all said. I basically just was looking to get the process of how you would go about saving the text input from one state and calling it in another state.
Thanks Again,
Brian
02-09-2011 08:33 PM
Did any of these suggestions help?
02-09-2011 08:33 PM
I just didnt want to copy and paste all my code on to here so that was just an example of what im trying to do.
02-09-2011 08:37 PM
haha sorry dude. didnt mean to pick apart your pseudo code. its probably best to try to reproduce your code so we know exactly what the problem is instead of trying to guess (like we did in the previous few posts in this thread). thanks. good luck!
02-09-2011 08:39 PM
Yea, you have to be careful. Bunch of us have eagle eyes on coding syntax -- things that tend to cause problems most of the time.
02-09-2011 08:44 PM
Alright sounds great thanks for all the help anyway I will repost my question late once I put the code back to the way I had it when I got the errors.
thanks again I will update the post with my real code