Wednesday, December 18, 2024
HomeComputer programmingAS3: How to Convert Number to String

AS3: How to Convert Number to String

Frequently, it is nice to convert numbers to strings in actionscript 3. For example, this will correct the error — 1067: Implicit coercion of a value of type Number to an unrelated type String.


In my neverending journey to teach myself actionscript, I have once again started pounding through some code.

In short to convert a number to a string, use the following construct:

text = String(number);

If you try to avoid this step, it’ll throw the following error…

1067: Implicit coercion of a value of type Number to an unrelated type String.

Here is some example code that will throw the error:


var time:Date= new Date();
var txt:String;
txt = time.milliseconds;

This code works correctly:


var time:Date= new Date();
var txt:String;
txt = String(time.milliseconds);

David Kirk
David Kirk
David Kirk is one of the original founders of tech-recipes and is currently serving as editor-in-chief. Not only has he been crafting tutorials for over ten years, but in his other life he also enjoys taking care of critically ill patients as an ICU physician.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

LATEST REVIEWS

Recent Comments

error: Content is protected !!