If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
New Developer
BrianMcPeek
Posts: 74
Registered: ‎02-09-2011
My Device: Torch 9850/64GB PlayBook
My Carrier: Verizon
Accepted Solution

How to save a text input value from one state and call that value at another state

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:smileyfrustrated: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:smileyfrustrated:cript>

 

 

 

<s:states>
 <s:smileyfrustrated:tate name="View1"/>
 <s:smileyfrustrated:tate name="View2"/>
 <s:smileyfrustrated:tate name="View3"/>
 <s:smileyfrustrated:tate name="View4"/>
 <s:smileyfrustrated:tate name="View5"/>
 </s:states>
<!-- View 1 -->
<s:TextInput includeIn="View1" x="276" y="65" id="A" focusIn="view1()"/>
<!-- View 2 -->
<s:TextInput includeIn="View2" x="276" y="65" id="B" focusIn="view2()"/>
<!-- View 3 -->
<s:TextInput includeIn="View3" x="276" y="65" id="C" focusIn="view3()"/>
<!-- View 4 -->
<s:TextInput includeIn="View4" x="276" y="65" id="D" focusIn="view4()"/>
<!-- View 5 -->
<s:TextInput includeIn="View5" x="276" y="65" id="Total"/>
<s:Button includeIn="View5"  id="Total" click="Add()"/>

 

 

 

Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: How to save a text input value from one state and call that value at another state

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!

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: How to save a text input value from one state and call that value at another state

Try

 

Total.text = String( TotalScore );

 

Also, the "add" function is case sensitive.  So the "click" callback should match.

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: How to save a text input value from one state and call that value at another state

[ Edited ]

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.

Please use plain text.
New Developer
BrianMcPeek
Posts: 74
Registered: ‎02-09-2011
My Device: Torch 9850/64GB PlayBook
My Carrier: Verizon

Re: How to save a text input value from one state and call that value at another state

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

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: How to save a text input value from one state and call that value at another state

Did any of these suggestions help?

Please use plain text.
New Developer
BrianMcPeek
Posts: 74
Registered: ‎02-09-2011
My Device: Torch 9850/64GB PlayBook
My Carrier: Verizon

Re: How to save a text input value from one state and call that value at another state

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. 

Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: How to save a text input value from one state and call that value at another state

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!

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: How to save a text input value from one state and call that value at another state

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.

Please use plain text.
New Developer
BrianMcPeek
Posts: 74
Registered: ‎02-09-2011
My Device: Torch 9850/64GB PlayBook
My Carrier: Verizon

Re: How to save a text input value from one state and call that value at another state

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

 

Please use plain text.