2 Replies Latest reply on Jan 12, 2016 6:47 AM by robdillon

    How to change the code to include Minimum number as well ...

    FlashLearner

      I have downloaded the file form the following website.

       

      Random number generator – Roy Tanck’s weblog

      http://www.roytanck.com/wp-content/uploads/randomnumber.zip

       

      There is a input box for Maximum number but no input box for Minimum number. I want to put I more input textbox on form for Minimum Number (Instead of "1"). So, how to change the following code to work properly? Suppose, if I want to get random number between 150 to 350, how can I?

       

      input_txt.restrict = "0-9";

       

       

      if( maxNr != undefined ){

        input_txt.text = maxNr;

      }

       

       

      switch(maxNr){

        case 1:

        easter_txt.text = "Wow ! You are LUCKY";

        break;

        case 42:

        easter_txt.text = "\"I checked it very thoroughly, it's 42\"";

        break;

        case 666:

        easter_txt.text = "Lucky Number !!!";

        break;

        case 999999999999999:

        easter_txt.text = "That's almost a quadrillion!";

        break;

        default:

        easter_txt.text = "";

        break;

      }

       

       

      go_btn.onRelease = function(){

        maxNr = Math.max( Number( input_txt.text ) , 1 );

        gotoAndStop("random");

      }

       

       

       

       

      stop();

       

      -------------------------------------------------------

       

      //maxNr = 999999999999999;

       

       

      initRandom = function(){

        var nr = Math.ceil(Math.random()*(maxNr));

        var nrString = "";

        for( var j=0; j<(maxNr.toString().length-nr.toString().length); j++){

        nrString += "0";

        }

        nrString += nr.toString();

        var holder = this.createEmptyMovieClip("holder",1);

        for( i=0; i<maxNr.toString().length; i++ ){

        var mc = holder.attachMovie("number","n"+i,i+10);

        mc._x = i*90;

        mc.anim_mc.gotoAndPlay( Math.floor(Math.random()*9) + 1 );

        this["iv"+i] = setInterval( this, "revealNumber", 2000 + (500*i), nrString.substr(i,1), i );

        }

        // scale (if needed) and center

        if( holder._width > Stage.width ){

        holder._width = Stage.width;

        holder._yscale = holder._xscale;

        }

        holder._x = Stage.width/2 - holder._width/2;

        holder._y = 40;

        // buttons

        back_btn.onRelease = function(){

        for(item in holder){

        holder[item].removeMovieClip();

        }

        gotoAndStop("intro");

        }

      }

       

       

      revealNumber = function( digit, i ){

        clearInterval( this["iv"+i] );

        holder["n"+i].gotoAndStop("done");

        holder["n"+i]["number_txt"].text = digit;

      }

       

       

      initRandom();

       

       

      stop();