Copy link to clipboard
Copied
Hello,
I am new to Flash and AS3 and I was trying to create a random number generator. I've included the code at the end. I have a button to generate the number and a dynamic text box called 'output' in which to display the number.
However, when I click "generate", I get the error message --> "1067: Implicit coercion of a value of type uint to an unrelated type String"
I assume this means Flash can't display the number as a string, but is there someway I can do this? Or something I've left out? Can you convert one data type to another? I know you can cast String into numbers, can you do it the other way?
Thanks for any help
CODE:
package
{
import flash.display.MovieClip
import flash.events.MouseEvent
public class Main extends MovieClip
{
public function Main()
{
generateButton.addEventListener(MouseEvent.CLICK, onGenerateButtonClick);
}
function onGenerateButtonClick(event:MouseEvent):void
{
var randNum:uint = Math.ceil(Math.random() * 100);
output_txt.text = randNum;
}
}
}
you can cast randNum as a string or use:
package
{
import flash.display.MovieClip
import flash.events.MouseEvent
public class Main extends MovieClip
{
public function Main()
{
generateButton.addEventListener(MouseEvent.CLICK, onGenerateButtonClick);
}
function onGenerateButtonClick(event:MouseEvent):void
{
var randNum:uint = Math.ceil(Math.random() * 100);
output_txt.text = randNum.toString();
}
}
}
Copy link to clipboard
Copied
you can cast randNum as a string or use:
package
{
import flash.display.MovieClip
import flash.events.MouseEvent
public class Main extends MovieClip
{
public function Main()
{
generateButton.addEventListener(MouseEvent.CLICK, onGenerateButtonClick);
}
function onGenerateButtonClick(event:MouseEvent):void
{
var randNum:uint = Math.ceil(Math.random() * 100);
output_txt.text = randNum.toString();
}
}
}
Copy link to clipboard
Copied
Thank you, works like a charm .
Copy link to clipboard
Copied
you're welcome.