We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


AS3 Concatenate integers

Mr_Splash asked
Medium Priority
Last Modified: 2013-11-11

I'm trying to concatenate three different integers to make a string with the code below. However I'm getting the following error.

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

Can anyone tell me how to do this?

Also I have very little knowledge of AS are the functions correct to produce; Random Number between 0-99 - Seconds since 01/01/1970 - Random Number between 0-99? for example...

If part 1 came back as 45, part two came back as 1234567890 and part 3 came back as 12 I would want the uniqueKey var to be 45123456789012 NOT 1234567947
var now:Date = new Date();
var uniqueKey:String = (Math.random()*99) + now.getTime() + (Math.random()*99);

Open in new window

Watch Question


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
			private function init():void{
				var now:Date = new Date();
				var uniqueKey:String = (Math.random()*99).toString() + "--" + now.getTime().toString()  + "--" +  (Math.random()*99).toString();
				textField.text = uniqueKey;
	<mx:Text id="textField" x="95" y="253" />

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
try this...

PS: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Date.html 
var now:Date = new Date();
// use .toString() to avoid addition
var uniqueKey:String = (Math.round(Math.random()*99)).toString() +" - "+ (now.getTime()).toString() +" - "+ (Math.round(Math.random()*99)).toString();
//1) Generate random number : 
var rn:Number = Math.random()*99
trace("rn = "+rn);
var addition:Number = rn+rn;
var concat:String = rn.toString() + rn.toString();
trace("addition = "+addition);
trace("concat = "+concat);
// Should both trace the same
trace("rn.toString() = "+ rn.toString());
trace("rn =  "+ rn);
trace("Math.round(rn) = "+Math.round(rn));
trace("Math.floor(rn) = "+Math.floor(rn));
trace("Math.ceil(rn) = "+Math.ceil(rn));
trace("uniqueKey = "+uniqueKey);

Open in new window


Thanks guys, I've split the points as both solutions were pretty much the same and were posted at the same time.

This is all that was needed in the end.
var uniqueKey:String = (Math.round(Math.random()*99)).toString() + "" +(now.getTime()).toString() + "" + (Math.round(Math.random()*99)).toString();

Please let me know if there is something incorrect with that.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.