• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Random No. Generator

Explorer ,
Apr 24, 2012 Apr 24, 2012

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;

        }

    }

}

TOPICS
ActionScript

Views

966

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 24, 2012 Apr 24, 2012

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();

        }

    }

}

Votes

Translate

Translate
Community Expert ,
Apr 24, 2012 Apr 24, 2012

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();

        }

    }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 24, 2012 Apr 24, 2012

Copy link to clipboard

Copied

Thank you, works like a charm .

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 25, 2012 Apr 25, 2012

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines