Using Math.random to go to random frames

Ask a Question related to Adobe Flash, Flex & Director, Design and Development.

  1. #1

    Default Using Math.random to go to random frames

    Hello everyone. My cerebral density is preventing me from seeing the solution to this problem.

    I have the following code which causes the user to jump to various frames in a timeline at random; the user clicks a component-button that actuates the addOn function below:

    generateNew = function () {
    n = Math.round(Math.random()*10);
    };
    addOn = function () {
    generateNew();
    gotoAndStop(n);
    if (_currentFrame == n){
    trace("the current frame is " + _currentFrame);
    }
    }
    stop();

    However, I don't want the user to go to the same frame twice during the session (before the page is reloaded). Can you suggest how I may prevent the same frame from recurring?

    Many thanks,

    Glen Gummess
    Instructional Designer
    University of St. Francis.
    Joliet, IL


    Glen Gummess webforumsuser@macromedia.com Guest

  2. Similar Questions and Discussions

    1. AIX testers wanted for Math::Random
      I recently received a bug report for Math::Random versions 0.67 and 0.68. The environment was AIX 5.2.0.0, perl 5.8.7 (or 5.8.8?), and gcc 4.0.1. I...
    2. Math-Random-MT-Auto-4.08.00.tar.gz
      As in previous versions, make test show a lot of NOK maybe because I use a 64 bit int compiled perl. Does anyone could correct this? TIA, --...
    3. math.random.whats wrong with my code?!!
      Why is it doing this?? What I want is for my mc to slide to a new random x position when it is less than 5 pixels away from its target, it keeps...
    4. Math random help
      Hi, My name is John. I have a MC 600 X 150. I want the clip to scroll continuously from right to left, while changing the y position randomly...
    5. Math::GMP tests and Crypt::Random fail on Compaq (Math::Pari related ??)
      Hi, I've been compiling Math::GMP for different OS's in order to use Net::SFTP and I have successfully compiled and used it for Solaris,...
  3. #2

    Default Re: Using Math.random to go to random frames

    just when random function generate a frame number save it to a variable and when you call again the random function compare it with this variable if they are equal call again random function compare again and again until the new number which is produced is different.

    your script will look likes:

    totalFrames=20;
    frames = new Array(totalFrames);

    newFrame = function () {
    _root.frameN = random(totalFrames-1);
    };

    function check() {
    for (i=1;i<=totalFrames;i++) {
    if (frames == 'visited') {
    _root.check = false;
    } else {
    frames = 'visited';
    _root.check=true;
    }
    }
    }

    addOn = function () {
    //i am not sure for the syntax of this loop
    while (_root.check != true) {
    newFrame;
    }
    gotoAndStop(_root.frameN+1);
    }

    addOn;
    stop();

    Do you agee ?





    elemental .std webforumsuser@macromedia.com Guest

  4. #3

    Default Re: Using Math.random to go to random frames

    I'll give it a try.

    Thank you!

    Glen


    Glen Gummess webforumsuser@macromedia.com Guest

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139