Professional Web Applications Themes

Using Math.random to go to random frames - Adobe Flash, Flex & Director

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 ...

  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. #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

  3. #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

Similar Threads

  1. AIX testers wanted for Math::Random
    By Geoffrey Rommel in forum PERL Modules
    Replies: 0
    Last Post: July 11th, 05:55 PM
  2. Math-Random-MT-Auto-4.08.00.tar.gz
    By gamo in forum PERL Modules
    Replies: 4
    Last Post: September 24th, 05:45 AM
  3. math.random.whats wrong with my code?!!
    By joe dc in forum Macromedia Flash Actionscript
    Replies: 1
    Last Post: March 3rd, 05:21 PM
  4. Math random help
    By johnk in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: January 12th, 11:16 PM
  5. Replies: 4
    Last Post: December 19th, 07:09 AM

Bookmarks

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