Random number generator

  • Frostbyt3
  • Graduate
  • Graduate
  • User avatar
  • Posts: 221
  • Loc: Corpus Christi, TX

Post 3+ Months Ago

Ok I have a small text field for my flash animation and i wanted it to look high tech.

It goes 30 fps and has 90 frames total...

I have the small text field with 8 numbers, only 0's and 1's as if it were binary, but I dont want to sit there and type random numbers for each 1 of the 90 frames.

I want it so the flash randomly generates 8 1's/0's combination in the text field for each frame, making it different for each frame.

Ive heard you can do this. Anyone know how? :)
  • OriginNO
  • Graduate
  • Graduate
  • User avatar
  • Posts: 137
  • Loc: the Glass City (Hometown: the NO)

Post 3+ Months Ago

Wut upper Frostbyt3.

It's fairly simple. First here is the actionscripts you will need.

generator = Math.round(Math.random());

The above action will set the variable equal to the random number generated between 0-1. The variable of course is your Dynamic text field. Make sure your text field is set to Dynamic and, uncheck everything, press [123]. For the variable name I used "generator". Size your text filed to fit a single digit and convert it to a movie and give it the instance name "generator". In the first frame of the generator movie put the above action. Make a new key frame at 25 and put the goto action back to frame 1. Now, create a new movie and name it "container". Drag the generator into the first frame and duplicate it 7 more times. Give the new generator duplicates new instance names. I just added the corresponding number. Line the generators up accordingly and your done. It will work as long as I didn't leave nothing out. If you want the files to check it out or you have any problems email me at: info@originnoinc.com
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

Simple, Simple, Simple :D

Press Ctrl+F8 to insert a new symbol, this will popup the little box asking what kind of symbol.
Select Movie Clip and click OK to start editing this new symbol (makes no difference what you name it).
Place your textbox at _x=0,_y=0 ,open the actions panel and make sure it says "Actions-Frame".

Now(in expert mode) place theese actions in the actions panel, replacing test2 with the variable of your textBox, & replacing 8 with the number of 1's & 0's you want.
Code: [ Select ]
this.onEnterFrame = function(){
    gnrtr = [];
    for(i=0; i<8; i++){
        gnrtr[i] = Math.round(Math.random());
    }
    test2 = gnrtr.join("");
}
  1. this.onEnterFrame = function(){
  2.     gnrtr = [];
  3.     for(i=0; i<8; i++){
  4.         gnrtr[i] = Math.round(Math.random());
  5.     }
  6.     test2 = gnrtr.join("");
  7. }


If your textBox has an instanceName instead of a variable replace test2 with textBoxInstanceName.text

Finally exit edit mode for that movieClip & place an instance of the new movieClip on the stage (good idea to give it an instance name incase you want to delete the onEnterFrame later :wink: )

What this is doing is each time the new movie clip entersFrame (30 times per second in your case) it fills an Array with N amount of random 1's & 0's, then joins() that array with NO seporator and applies it to the textBox.

:D
btw, yes this is the same joebert from PixelAcres :wink:

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 12 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.