February 2010
M T W T F S S
« Jan   Mar »
1234567
891011121314
15161718192021
22232425262728

Convert text to number

Problem

I need convert text into number. Or number into text:)

Solution

Need use type conversions

Detailed explanation

Please create file and add some components like on the image, also write instance names:
inttostring

Add code to the ACTIONS area:

// first way (i like it becaus don't need create new variable)
myBtn.addEventListener(MouseEvent.CLICK, plus);
function plus(event:MouseEvent):void {
trace("button press");
rez.text = String(int(a.text)+int(b.text));
trace(rez.text);
}

// second way, need add new variable 'c'
/*
var c;

myBtn.addEventListener(MouseEvent.CLICK, plus);
function plus(event:MouseEvent):void {
trace("button press");
c=int(a.text)+int(b.text);
rez.text=c;
trace(c);
}
*/

Now test your work.

inttostring2

Read more about Type Conversions.

In attached files you can find all source files.

Source:
int_to_string_convert

Thank you for reading!

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>