Skip navigation
Bawlar
Currently Being Moderated

Random No. Generator

Apr 24, 2012 8:02 PM

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;

        }

    }

}

 
Replies
  • kglad
    72,189 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 24, 2012 8:16 PM   in reply to Bawlar

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

            }

        }

    }

     
    |
    Mark as:
  • kglad
    72,189 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 25, 2012 6:22 AM   in reply to Bawlar

    you're welcome.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points