Random Question
how to change randomly the frame of some movie! like random goto and play 3 but i want to be random only from 0 to frame 50 of 100 frames!
suggestions? thanx in advance
FlashKit > Flash Help > Flash ActionScript
Posted on: 09-21-2004, 11:47 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Random Random Random Timer... Problems
Heyy guys. I know you guys know this stuff backwards & forwards so maybe you can help.
This is a 2 part problem. Part 1 is Im trying to create a timer that functions at random intervals, the function in this case is playing a MC of a car driving on a freeway in 1 to 10 second intervals to give the feeling of, well, randomness. (I've attatched the .fla file if that'll help).
So it works, but not quite as it will generate intervals only twice before it repeats the second interval over and over. So the car will 'drive' in say, 7 seconds the first time and then it will drive in 3 seconds, then again in 3, and in 3 and in 3 seconds. Ive tested it so much I know its not coinsidence.
Here's the code Im using (located in the freeway MC):
var interval:Number = random(10)+1;
function someCodeToRun() {
_root.freeway.diffcars.drive01.gotoAndPlay(2);
}
setInterval(this, "someCodeToRun", interval*1000);
Part 2 is I also wanted the cars to be different colors, which is why there is a diffcars MC with different frames of cars, but now Im not even sure I was headed in the right direction with that.
Ultimately Id love to have different colored cars driving on the freeway at different intervals. Can anyone figure this out?
PLEASE HELP - URGENT Load Random Swfs From Individual Random Sets
I have two target mcs I would like to load different random swfs into
I have eight folders (a-h), each with 12 swfs (001-012)
I need to load a random swf (001-012) from a random folder (a-h) into the "card1" mc
I have figured out how to specify which one I want:
loadMovie("a/a001.swf","card1")
stop();
however, I need it randomized....
then, I need to load another random swf into my "card2" mc (001-012) from another random folder (a-h, ...except for the folder from which the first swf was loaded)
can somebody please help??????
Random Movie Clips To Play For Random Amount Of Time
hi,
i am loading external movieclips randomly into 4 seperate emptymovies, i now need a way to get these random clips that i am loading to play for a random amount of time and then load the next clip.
i need some help with the code...
how do i get the clips to loop, then assign each a random number and have flash check if the random num is = to current frame...if it is, have that clip stop and a new one load?
i have no idea how to write the code for this
any help would be great
thanks
this is what i was given so far..but don't know what to do with it.
Code:
var rnd = Math.round(Math.random(mc._totalframes));
mc.onEnterFrame = function() {
this._currentframe >= this._parent.rnd ? unloadMovie(this) : null;
}
Script Needed: Random Picture On Random Place By Click
I have a small question about a script I'm trying to find. I don't have a lot of experience with Flash, but I have to do this thing for school for which I need this script for my website.
I need a script which does the following: When you click on a button (or just on any place if the first is not possible) with you mouse, there appears a random picture (one out of ten or something) on a random place in a field (so not the whole page).
I hope you understand what I mean. I don't know the script, I only know that it's supposed to exist :) Does anybody know this script or where I can find such a script?
Thanks for helping me!
Elfie
Help: Multipule Random Positioned Duplicate Random Movie
Does anyone know a way that i can produce a button that when rolled over will duplicate x amount of movies each with random _x and _y positions? Basically i have a movieclip that will
gotoandPlay(math.Round((math.Random()*10)+1)
which randomises that frame that is played. This instance will then do some form of tweening and then gotoandPlay(1) again. I need a script that will then keep generating more duplicate movie clips whilst a button is moused over. i tried the following
on(mouseover){
i = 0;
rand_num = math.Round((math.Random()*29)+1);
while(i<20) {
duplicateMovieClip(_root.movie, "movie"+i,i);
setProperty("movie"+i, _x, _root.movie._x+(rand_num*5);
setProperty("movie"+i, _y, _root.movie._y+(rand_num*5);
i++
}
}
where movie = movieclip name
but this seems to generate all the clips on top of each other @ different depths. I want movies that are all in different positions. Can you help?
Random Movieclip @ A Random Partly Defined Position
Ok I´ve searched this forum to death but i didn´t REALLY
find the answer to my question! I think it can´t be that
difficult but i´m new to action-script and so i gotta hope
u´ll know the answer :
I´ve got an movie. (uh yeah ^^) in this movie there are
many movieclips that contain animations. now i want these
mcs to appear randomly @ a random position of a few defined
positions.
I really got NO idea how to do this !*prayinforyahelp*
ok thx 8]
Detecting Which Random AttachMovie Loaded From Random Array
I'm building a Freecell type card game. I've got an array that loads all of the cards (actually, the linkage names for each card loaded from the library with attachMovie). I randomize the array before I "deal the cards" onto the stage.
Here's a little code snipet where "deal" starts off equaling 0 and "cardDeck" is the value from my array (for example, c5 equals 5 of Clubs):
Code:
if (deal<52) {
_root.createEmptyMovieClip("card"+deal, deal);
_root["card" + deal].attachMovie(cardDeck[deal],cardDeck[deal],deal);
deal++
}
There's more, of course. My problem is - How can I detect which card loaded into which movie? For example, I know I have a movie called _root.card6 at the bottom of the first column, how can I know what card is loaded into _root.card6?
Movieclip Showen In Random Places At Random Time
How can I make my movieclip appeare in diffirent places at diffirent time? And the movie clip is this flying mobilephones(you can see it in swf http://www.hot.ee/at03/flying-mobs.swf).
Thanx in advance!
Random Rotation To Equal Random Movement Direstion?
k i finally got it so that my things randomly move around the screen and have walls etc etc.. anyways now i wanna know how to make it so that my randomly moving ship will rotate to face there direction if you want i can post the code i am using for random movement and thanks in advance
Load Random Swfs From Two Differnet Random Sources
I am in the process of creating a VS Card game in Flash. It is basically a game where you can choose either one card or another, each randomly pulled from one of the eight different sets. The first card (or swf) can be pulled from any of the 8 sets (out of a total of 12 cards in each set))..and will load into a targetMC, and the second must be pulled randomly from any of the 8 sets except from the folder where the first card was chosen and load onto the second targetMC.
after the winning card is chosen, it will display winning animation (and send data off to a dynamic bargraph program), and then the main movie will reload two random cards from differnt sets.
can anybody help me on how to set this up??
Random Pics In Grid With Random SetInvertval Or Similar
Ok I think my subject makes sense perhaps a link to an example to a site I'm "inspired" by will make more sense http://www.stevenlippman.com/ So I'd love to make a front page like this one anyone like to point me in the right direction?
Random Motion Along Specified Paths At Random Intervals?
I am working on a site right now and I have a collaged background image with a faded ciruit board looking series of intersecting lines.
I would like to create a subtle gradated sphere to simulate a signal travelling along the cicuits. However, I would like several instances of the signal (or pulse) to take different routes and begin and end randomly.
Is there a way to set-up possible routes with a motion guide and then tell objects to randomly choose those routes at random intervals???
Need Code For Random Scenes Not Random Movies
Hi
I need a code for loading random scenes for a flash intro. I have only found a code for loading random movies but I don't want to have to do the preloader for every movies because it would destroy the whole thing on how it loads.
Any help is appreciated.
Thanks!!
Goto Random Frames At Random Times?
hey,
it is basically the title i would like the movie to jump to either frames 8 or 9 at random times. the movie stays on frame 1 unless told to move.
please help
i have MX and i would also like a button to do a similar task except for the random time thing
thanks in advanced
Random Background With Random Text File
I am trying to create a resizable flash file that will act as a background for my html/css website. Within the flash I want to have a script that randomly loads a jpg file from a specific folder on my server as well as a correlating txt file for that background. Here is an example of what I mean.
Say there is a movieclip named "background" and then a dynamic text area named "info" in the lower left-hand corner of the flash movie. I want a script to randomly load a jpg file (say 234.jpg) from a folder named "backgrounds" on the server. I also want it to load the correlating text file into the dynamic text area (234.txt) from a folder named "info". How would I do this and what would the script be?
NOTE: the names of the jpg and txt files would be 1.jpg, 1.txt, 2.jpg, 2.txt, etc.
Thank you for any help you can give!
-- K
Playing A Random Moive At Random Intervals
ello
basic rundown:
i have five movies on the stage that are stopped
i want to play one of the five at random intervals
here is what i knocked up:
Code:
minTime = 1000;
maxTime = 5000;
setInterval(function () {
trace("go bubbles");
_root.bub = "bubbles"+(random(6)+1);
_root.bub.play();
trace(bub);
}, Math.ceil(Math.random()*(maxTime-minTime+1))+(minTime-1));
it outputs random bubbles2, bubbles5 etc to the bub variable (as seen in the trace) but when i try to create a string so it plays the bub variable, it doesnt work.
yes i have the bubble movies labeled
im also not sure if the random interval changes each time, is there a way to do this?
thanks for any help
my priority is for the script to tell a random "bubbles" movie to play
thanks
Random Quotes On Random Spot Flashing
I want to display random quotes from an array and have them fade in at a random spot that fits them inside the flash document, wait for like 2 seconds, fade out, then after like 3 seconds, another one fades in and it keeps repeating over and over. How would I do this? Thanks.
Creating 10 Random Circles With Random Colors
hi folks.
I´m trying to write a simple function: create 10 circles (with random coordinates) and the circles should have random colors.
How can I assign the random colors? Is there an AS function that can help me?
Using Math.random() To Generate 14 Random Cards
I am relatively new to Actionscript and Flash, but not to web development in general. I have made a small matching game of pairs, where you have to find the pairs and remember where the cards where.
You can see the game here: http://www.mrmen.net/flash.php?game=mrmenmatch
I found a tutorial on how to do this and edited as much as I could after having previous knowledge of PHP and Javascript (as Actionscript has the same C style syntax) and made it display how I wanted it to.
However the code reads from a directory of images. I have 80 images in this directory that I want to use, but as there are only 28 squares (therefore only 14 images are used) it takes the first 14 images in the directory and uses them in a random order to place them in different positions. I want it to be able to randomly select 14 of the 81 images in the directory if possible.
I have posted the whole script below, but the part that I am interested in is where it refers to the location of each image ("http://www.mrmen.net/flash/matchImages/...")
Code:
// Gamefield settings
// EDIT HERE
card_w = 100
card_h = 100
card_wdistance = 10
card_hdistance = 10
// STOP EDIT
card_dw = card_w+card_wdistance
card_dh = card_h+card_hdistance
/*row_card = Math.floor((Stage.width-card_wdistance) / card_dw)
col_card = Math.floor((Stage.height-card_hdistance) / card_dh)*/
row_card = 7;
col_card = 4;
n_card = col_card*row_card%2 == 0 ? col_card*row_card : (col_card-1)*row_card
imgs_n = n_card/2
// CENTER THE IMAGE IN THE CARD
centerImage = function(target){
target.front._visible = false
target.front.container._x -= target.front.container._width/2
target.front.container._y -= target.front.container._height/2
}
// ---------------------------------------------
empty = new Array()
function createCard(n,w,h){
empty.push(n)
this.createEmptyMovieClip('card'+n,n)
with(this['card'+n]){
lineStyle(0,0x000000,100)
beginFill(0xFF9900,120)
moveTo(w/2,0)
lineTo(w/2,h/2)
lineTo(-w/2,h/2)
lineTo(-w/2,-h/2)
lineTo(w/2,-h/2)
lineTo(w/2,0)
endFill()
createEmptyMovieClip('front',1)
front.createEmptyMovieClip('container',2)
front.createEmptyMovieClip('backgr',1)
with(front.backgr){
moveTo(-w/2,-h/2)
lineStyle(0,0x000000,0)
beginFill(0x333333,100)
lineTo(w/2,-h/2)
lineTo(w/2,h/2)
lineTo(-w/2,h/2)
lineTo(-w/2,-h/2)
endFill()
}
front.onEnterFrame = function(){
tot = this.container.getBytesTotal()
car = this.container.getBytesLoaded()
if(tot == car && tot > 200){
this._parent._parent.centerImage(this._parent)
delete this.onEnterFrame
}
}
}
}
selcards = []
function placeImages(){
act_img = 1
for(img=0;img<imgs_n;img++){
for(k=0;k<2;k++){
act = Math.round(Math.random()*(empty.length-1))
this['card'+empty[act]].img_id = act_img
this['card'+empty[act]].front.container.loadMovie("http://www.mrmen.net/flash/matchImages/img"+act_img+".gif")
this['card'+empty[act]].onRelease = function(){
this.rotateCard(0,0)
this.enabled = false
MovieClip.prototype.enabled = false
}
empty.splice(act,1)
}
act_img++
}
}
MovieClip.prototype.rotateCard = function(v,i){
this.operazione = v == 0 ? +0.1 : -0.1
this.incremento = i == 0 ? 100 : 10
selcards.push(this._name)
this.onEnterFrame=function(){
this.incremento += this.operazione;
this._xscale = (100*Math.sin(this.incremento));
if(this._xscale > 0){
this.front._visible = v==1 ? false : true
}
if(this._xscale >= 99 ){
delete this.onEnterFrame
selcards.length < 2 ? MovieClip.prototype.enabled = true : null
v==0 && selcards.length > 1 ? checkCards() : null
}
}
}
function generateGameField(cards,distance,hdistance){
Ypos = card_h/2 + hdistance
Xpos = card_w/2 + distance
for(c=0;c<cards;c++){
createCard(c,card_w,card_h)
if(c%row_card==0 && c>0){
Ypos += this['card'+c]._height + hdistance
Xpos = card_w/2 + distance
}
this['card'+c]._x = Xpos
this['card'+c]._y = Ypos
Xpos += this['card'+c]._width + distance
}
placeImages()
}
generateGameField(n_card,card_wdistance,card_hdistance)
playerScore = 0
playerTries = 0
function checkCards(){
if(this[selcards[0]].img_id == this[selcards[1]].img_id){
playerScore++
displayScore.text = playerScore;
eval(selcards[0])._visible = eval(selcards[1])._visible = false
} else {
eval(selcards[0]).rotateCard(1,1)
eval(selcards[1]).rotateCard(1,1)
eval(selcards[0]).enabled = eval(selcards[1]).enabled = true
}
selcards = []
playerTries++
displayTries.text = playerTries;
if(playerScore == 14) {
finishMessage._visible = true;
} else {
MovieClip.prototype.enabled = true
}
}
Has Anyone Tested How Random Is The Math.Random() Function?
Just wondering whether anyone out there has ever run any tests on how random the Math.Random() function is as a random number generator?
I've been asked me to test it to prove that it is random and it seems a pointless waste of time, so I'm hoping to get evidence from elsewhere to convince the powers that be that there's no need to run the tests.
I've googled for it but come up with nothing so I'm hoping there might be someone out there who has already done the research?
Math.random With Non-repeating Random Choices
I'm trying to create a puzzle game wherein pieces pop up randomly, but each piece will pop up randomly only once. The code I've used to start is:
ActionScript Code:
pics.gotoAndStop(Math.floor(Math.random()*4));
where I've placed a movie clip containing all of the pieces on the main timeline and named it "pics".
How can I make it such that each piece is eliminated from random pick once it has been picked?
Random Location For A Random Movie Clip
I have various movie clips which I need to appear in one of four locations randomly. I need the movie clip to also be random. I also need more than one movie clip on stage at the same time. I believe the following needs to be used:
Math.random
duplicateMovieClip
I also believ that the method needs to be generic. Apart from that I am stuck.
Any help/ideas are appreciated.
Hope my question makes sense?
Random Function & Unique Random Numbers
Hello, after some searching i can't seem to find any good explanation to how and why i should use the Math.random() function so maybe i should explain how a function i need should work and someone maybe has some ideas.
I'm making a guessing program where you guess the right answer.
The function i have now randomly selects a number from 0 to 5 and then put's these five numbers into an array, the thing is that i need the numbers to be unique and i have no idea on how to make this.
Another thing i need to do is between these numbers that the random() function gets one is to be removed and instead i put the right answer there so now i also need one of the randomizes numbers to not be the right answer.
Also, how should a Math.random() function call look like so i can edit the range of numbers to randomize from?
Placing Random MC On Stage, With Random MC Inside
Hi guys
I have 4 movie clips in the library, each with 5 frames in them.
What I need, is at a random interval, one of these movie clips to be placed on the stage in a set place (each of the 4 will only appear on one particular place on the stage) and play through the frames.
Also, I need the item that is on each frame of each movie to randomly load from an array of 7 items, each with their own stored characteristics.
Anyone able to give me some pointers? im using mx2004
cheers
Flash 8 Random Sound, Random Movieclip
Dear people, happy greetings to you all.
I would like to find some way of using a simple variable structure to do 2 things:
Pick and play a random sound from say - a selection of 5 sound files.
Do something similar with movieclips.
If you could show me where some relevant tutorials are that show how to do this or can supply some indicative code I would be most grateful.
many thanks
julie
*
Random Letters In Random Places Within And Around A String
This will be very confusing to explain so i will use a few examples along the way to describe what i am trying to do.
So first: I saw a game on GSN called "Camouflage". If any of you have seen it, great, that's what i want to make. If not: There are phrases hidden in a sea of text and slowly one by one the letters not included in the phrase are taken away to reveal the final phrase. You ring in to guess at what the phrase is.
Example:
K W R I R O K U D P A S
Next round:
K R I R O K U D P A S
Next round:
K W R I R O K U D P A
And it continues until only KIRUPA is left.
About every second and a half a letter not included in the phrase is taken away and the amount of points you win goes down by 10.
I have the basic game mechanics down as well as a random letter generator, but i do not know how to randomly place random letters in a string and how to make them go away after a period of time.
Here is what i have so far:
The game mechanics: http://www.davidzych.com/marc/camouflage.swf
(Click start to get it going, then click answer to stop the clock then type in the word in the middle of the screen then click on the box to the right. Repeat to go again.)
And the random letter generator: http://www.davidzych.com/marc/randomLetterTest.swf
(click on the black box to generate random letters)
And the source code for each:
Note: I'm making it in Flash CS3 and i was too lazy to create the text fields and boxes with AS so i didn't. Also i couldnt' think of good names for functions.
Camouflage:
Code:
stop();
var totalScoreNumber:Number = 0;
totalScore.text = "0";
var countDown:Timer = new Timer(1300, 999);
var countDown2:Timer = new Timer(1000, 999);
var scoreNumber:Number = 100;
var timeLeft:Number = 5;
score.text = scoreNumber.toString();
start_btn.buttonMode = true;
start_btn.addEventListener(MouseEvent.CLICK, startTimer);
countDown.addEventListener(TimerEvent.TIMER, restartLose);
countDown2.addEventListener(TimerEvent.TIMER, restartLose2);
stage.addEventListener(Event.ENTER_FRAME, timerCheck);
function timerCheck(event:Event):void
{
if(scoreNumber == 0)
{
response_txt.text = "Out of time!";
submit_btn.removeEventListener(MouseEvent.CLICK, answer);
start_btn.addEventListener(MouseEvent.CLICK, startTimer);
countDown.stop();
start_btn.buttonMode = true;
submit_btn.buttonMode = false;
answer_btn.buttonMode = false;
}
else if(timeLeft == 0)
{
response_txt.text = "Out of time!";
submit_btn.removeEventListener(MouseEvent.CLICK, answer);
start_btn.addEventListener(MouseEvent.CLICK, startTimer);
countDown2.stop();
start_btn.buttonMode = true;
submit_btn.buttonMode = false;
}
}
function startTimer(event:MouseEvent):void
{
start_btn.buttonMode = false;
answer_btn.buttonMode = true;
timeNumber.text = "";
response_txt.text = "";
answer_txt.text = "";
countDown.start();
scoreNumber = 100;
score.text = scoreNumber.toString();
answerNumber = Math.floor(Math.random() * answers.length);
hint_txt.text = hints[answerNumber];
answer_btn.addEventListener(MouseEvent.CLICK, stopTimer);
start_btn.removeEventListener(MouseEvent.CLICK, startTimer);
}
function stopTimer(event:MouseEvent):void
{
countDown.stop();
countDown2.start();
timeLeft = 5;
submit_btn.buttonMode = true;
answer_btn.buttonMode = false;
timeNumber.text = timeLeft.toString();
submit_btn.addEventListener(MouseEvent.CLICK, answer);
answer_btn.removeEventListener(MouseEvent.CLICK, stopTimer);
}
function restartLose(event:TimerEvent):void
{
scoreNumber -= 10;
score.text = scoreNumber.toString();
}
function restartLose2(event:TimerEvent):void
{
timeLeft -= 1;
timeNumber.text = timeLeft.toString();
}
var answers:Array = ["yes", "no", "maybe", "not", "pirate", "adobe", "macromedia", "flash"];
var hints:Array = ["yes", "no", "maybe", "not", "pirate", "adobe", "macromedia", "flash"];
var answerNumber:Number = Math.floor(Math.random() * answers.length);
function answer(event:MouseEvent):void
{
start_btn.buttonMode = true;
submit_btn.buttonMode = false;
countDown2.stop();
submit_btn.removeEventListener(MouseEvent.CLICK, answer);
start_btn.addEventListener(MouseEvent.CLICK, startTimer);
if(answer_txt.text == answers[answerNumber])
{
response_txt.text = "Correct!";
totalScoreNumber += scoreNumber;
totalScore.text = totalScoreNumber.toString();
}
else
{
response_txt.text = "Incorrect!";
}
}
Random letter:
Code:
var letter1:Number = 0;
var letter2:Number = 0;
var letter3:Number = 0;
var letter4:Number = 0;
var letter5:Number = 0;
var letter6:Number = 0;
var letter7:Number = 0;
var letter8:Number = 0;
var letters:Array = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
button_btn.buttonMode = true;
button_btn.addEventListener(MouseEvent.CLICK, randomLetterFix);
function randomLetterFix(event:MouseEvent):void
{
letter_txt.text = "";
randomLetter();
}
function randomLetter()
{
letter1 = Math.floor(Math.random() * 26);
letter2 = Math.floor(Math.random() * 26);
letter3 = Math.floor(Math.random() * 26);
letter4 = Math.floor(Math.random() * 26);
letter5 = Math.floor(Math.random() * 26);
letter6 = Math.floor(Math.random() * 26);
letter7 = Math.floor(Math.random() * 26);
letter8 = Math.floor(Math.random() * 26);
letter_txt.text = letters[letter1] + letters[letter2] + letters[letter3] + letters[letter4] + letters[letter5] + letters[letter6] + letters[letter7] + letters[letter8];
}
So i have an array of phrases that i want hidden dispersed in other random letters and i want the random letters not a part of the phrase to disappear when i run a function.
Sorry that this was a lot of reading and explanation but i figure that i'd over explain it so there isn't any confusion.
Again - The .swfs i have right now work GREAT! It's just the randomly dispersing the phrases that i don't know how to do along with taking these letters away.
Random Movement, Random Opacity?
I want to create a mc, where a box(50x200) should duplicate itself, and change width randomly. But width should stay in ranges between 50 - 250 px. The boxes should move from left to right, right to left randomly. Also they should have random opacity and random colors(different variations of blue,and red). When the boxes overlap=the opacity should change accordingly, also color changes as they mix. Is creating something like this, or similiar possible?
If so does anybody have examples.
Thnx
Calling Random Mc's At Random Times?
i have three animations (ant's crawling)
I would like them to be randomly called up
ie:
on (rollover) {
tellTarget ("ant") {
gotoAndPlay(2);
}
}
but not with a button... is it possible to get them to crawl around.. say
like every 30 seconds call up mc 1, 2 or 3 and play it?
Making A Not So Random Random Variable
Code:
question.text = random (12);
Having made question.text a random number up to 12 how can I repeat this, but ensure that the variable is different from its original value?
Many thanks!
Random Paths (NOT Random Motion)
I only know the basics in Flash so I'm not quite sure how to word this..
Say I've got one linear motion guide that then splits in three directions. I'd like my movie clip to travel on the path and then randomly choose which of the three paths to take. I have no idea where to begin and have searched for scripts - only random motion scripts have popped up through. Hopefully, in the end, I'd have multiple objects travelling on random paths - similar to this - http://www.flashkit.com/movies/Scrip...1926/index.php.
Thanks in advance.
Random Sound, Random Movieclip,
Dear people, happy greetings to you all.
I would like to find some way of using a simple variable structure to do 2 things:
Pick and play a random sound from say - a selection of 5 sound files.
Do something similar with movieclips.
If someone could point me in the direction of any tutorials that show how to do this or can post some indicative code I would be most grateful.
Thanks in advance.
julie
x
Making Random Backgrounds More Random W AS
Hello,
Im working on my site and I have a random background script setup. Heres the code that Im using now.
Code:
choice = Math.round(Math.random()*4);
switch (choice) {
case 0 :
_root.background.loadMovie("background1.swf");
break;
case 1 :
_root.background.loadMovie("background2.swf");
break;
case 2 :
_root.background.loadMovie("background5.swf");
break;
case 3 :
_root.background.loadMovie("background7.swf");
break;
case 4 :
_root.background.loadMovie("background8.swf");
break;
}
Now I love the way thats its working and but one thing that is kinda crappy is that sometimes it suffers from repeating the same background a couple of times before going to another random background. Now I know that its because the script is working properly but can anyone think of a method that I could use to make it not be able to pull up the last background that it has already loaded? I dont want to make it static because not only do I have this setup for when you enter the site but also its random when you click on one of the nav buttons because I want to try to keep my site dynamic.
Any ideas?
Thanks in advance.
Random Movement AND Random Speed
So I got this from the tut on this site and it's works great.
I can't figure out though how to make the speed random as well as the movent.
I want all my little clips to move at random speeds in adition to direction.
Any clues?
Thanks!
---------------------------------------
function getdistance(x, y, x1, y1) {
var run, rise;
run = x1-x;
rise = y1-y;
return (_root.hyp(run, rise));
}
function hyp(a, b) {
return (Math.sqrt(a*a+b*b));
}
MovieClip.prototype.reset = function() {
//specify the width and height of the movie
width = 600;
height = 400;
//-------------------
var dist, norm;
this.x = this._x;
this.y = this._y;
this.speed = Math.random()*4+5;
this.targx = Math.random()*width;
this.targy = Math.random()*height;
dist = _root.getdistance(this.x, this.y, this.targx, this.targy);
norm = this.speed/dist;
this.diffx = (this.targx-this.x)*norm;
this.diffy = (this.targy-this.y)*norm;
};
MovieClip.prototype.move = function() {
if (_root.getdistance(this.x, this.y, this.targx, this.targy)>this.speed) {
this.x += this.diffx;
this.y += this.diffy;
} else {
this.x = this.targx;
this.y = this.targy;
if (!this.t) {
this.t = getTimer();
}
if (getTimer()-this.t>1000) {
this.reset();
this.t = 0;
}
}
this._x = this.x;
this._y = this.y;
};
--------------------------------
onClipEvent(enterFrame){
move();
}
Random Flash N Random Image
Basically I have 5 flash movies and 3 images and I want to show them randomly using dreamweaver.. anybody knows how to do it?
[F8]random Scaling, But With Random Movement?
i am a bit lost. i make a prototype function that randomly scales a box when i click on the stage. i got the scaling right, but why does it move around when it scales?
here is the swf: scaleEase
here is the code:
ActionScript Code:
MovieClip.prototype.scaleEaseTo = function(ease){ onMouseDown = function () { newWidth = 1 + Math.random() * 250; newHeight = 1 + Math.random() * 250; }; this._xscale += (newWidth - this._xscale) / ease; this._yscale += (newHeight - this._yscale) / ease;};dot.onEnterFrame = function(){ scaleEaseTo(5);};
thanks in advance.
Random Images + Random Timing
Is it possible to display random images, along with a unique amount of air time for each image?
I have a section that will display a company logo for a particular amount of time, according to its sponsorship level – being either 20, 10, 7, or 5 seconds.
Approximately 20 images are being used (JPEG, at 240px wide x 200px tall).
Rising Shapes...random...yet Not So Random.
Hey all, Im trying to get rising boxes to float up from the bottom of the screen and move up and somewhat to the right. And before I get told i know, i know I looked at all the snowfall/bubble tutorials but I can't finesse them to work they way I need.
Heres an example of pretty much exactly what im looking for ( http://www.youtube.com/watch?v=fGNvRcS9A7w [see all those cool little floating arrows in the background?] ).
I'm not worried about having variable alpha, variable sizes and even the trajectory I want to be exactly the same for each of the blocks. The only random things I need is the positioning so they don't look on the same horizontal/vertical line... I also have the flash movie resize to the users window so If its at all possible to have the blocks always appear from off screen no matter where that bottom line may be that would be frickin' fantastic!
Random Images, Random Positions?
Hey there.
I want to add some depth to my background and what I was thinking was to have a simple animation appear at random each time a differant size, position angle ect, and if possible have it attach the animation more the once at a time.
Cheers.
Making Random Backgrounds More Random W AS
Hello,
Im working on my site and I have a random background script setup. Heres the code that Im using now.
Code:
choice = Math.round(Math.random()*4);
switch (choice) {
case 0 :
_root.background.loadMovie("background1.swf");
break;
case 1 :
_root.background.loadMovie("background2.swf");
break;
case 2 :
_root.background.loadMovie("background5.swf");
break;
case 3 :
_root.background.loadMovie("background7.swf");
break;
case 4 :
_root.background.loadMovie("background8.swf");
break;
}
Now I love the way thats its working and but one thing that is kinda crappy is that sometimes it suffers from repeating the same background a couple of times before going to another random background. Now I know that its because the script is working properly but can anyone think of a method that I could use to make it not be able to pull up the last background that it has already loaded? I dont want to make it static because not only do I have this setup for when you enter the site but also its random when you click on one of the nav buttons because I want to try to keep my site dynamic.
Any ideas?
Thanks in advance.
Help With Random Frames And Random Movies...
Hi all,
Great site!!!!
Anyway, I have an idea that i am working on and need some help....
I have 5 different movieclips that are about 300 frames long each (30 fr/sec). When Scene1 is played, I want to have 10 movie clips running, each beginning at a random frame, and each being one of the 5 movieclips chosen at random.....
Right now all I have is one of the clips running at a time, and the clip randomly changes every time Scene1 is reloaded.
I want multiple (10) random clips (chosen from the 5 clips) to be introduced at random frames throughout the movie to create a continuous random effect....
Any help would be appreciated....
Thanks,
Asheesh
Random Movement AND Random Speed
So I got this from the tut on this site and it's works great.
I can't figure out though how to make the speed random as well as the movent.
I want all my little clips to move at random speeds in adition to direction.
Any clues?
Thanks!
---------------------------------------
function getdistance(x, y, x1, y1) {
var run, rise;
run = x1-x;
rise = y1-y;
return (_root.hyp(run, rise));
}
function hyp(a, b) {
return (Math.sqrt(a*a+b*b));
}
MovieClip.prototype.reset = function() {
//specify the width and height of the movie
width = 600;
height = 400;
//-------------------
var dist, norm;
this.x = this._x;
this.y = this._y;
this.speed = Math.random()*4+5;
this.targx = Math.random()*width;
this.targy = Math.random()*height;
dist = _root.getdistance(this.x, this.y, this.targx, this.targy);
norm = this.speed/dist;
this.diffx = (this.targx-this.x)*norm;
this.diffy = (this.targy-this.y)*norm;
};
MovieClip.prototype.move = function() {
if (_root.getdistance(this.x, this.y, this.targx, this.targy)>this.speed) {
this.x += this.diffx;
this.y += this.diffy;
} else {
this.x = this.targx;
this.y = this.targy;
if (!this.t) {
this.t = getTimer();
}
if (getTimer()-this.t>1000) {
this.reset();
this.t = 0;
}
}
this._x = this.x;
this._y = this.y;
};
--------------------------------
onClipEvent(enterFrame){
move();
}
Random() Vs Math.random()
Sigh..I know this has been asked before but I can't seem to find the thread :/
Is there any speed advantage (or any advantage at ALL) to using 10*Math.random (which generally must be used with a Math.ceil, floor, or round) over the random(10) of yesteryear?
It really does seem that in most cases you'd be using an integer rather than a floating point...
Arctic
Math.random() Vs. Random()
I made a simple "tip of the day" type thingy. Have an array of 20 items or so. Make call to random number generator, whatever, i'm not really asking about the movie...
When I was doing this (with about three hours of staring into the actionscript dictionary under the help menu) I came across them (Macromedia) saying that math.random is kind of being pushed out in favor of random. Any of you know why this is? (note: i'm using Flash 5)
Also, of all the random number generators, Flash's must be the worse i've ever seen... Anyway of getting things a little more random? (randomer?) Whatever, you know what I mean. I know, or atleast know that in most RNG's it is based off the system clock. Still, it seems like Flash's is worse... Any comments? suggestions? Questions?
-darque9
Random Vs. Math.random
Hi!
Trying to learn Flash5 ActionScript before moving to MX and noticed that I used alot of Flash4 actionscript in my Flash works...
I'm used to use 'random(x)', but understood that it's better with 'Math.random()'. Now how does it work, exactly?
If I want to jump to a random frame between 1 - 10 I used 'random(10)+1;' Now with Math.random, if I have got it right I have to do two things different. First I have to do it like this: 'Math.random()*9 +1;' (because it gives a number between 0 and the specified number and not between 0 and the specified number minus one). Second I need to put it all inside a Math.round function - like this: Math.round(Math.random()*9 +1); so that I will get an integer and not float. I find this to be a bit of over work... Is there a simpler way?
thanks!
Random() Vs Math.random()
ok, hopefully someone can explain to me why
random(6)+1//which I understand is now depricated
has been exchanged with this:
Math.ceil(Math.random()*6+1)//hope I got that right
isn't the first one easier?
Adam
Random Pic In A Random MC Problem
ok I have below script and it works fine. but I need to modify it and I'm at a loss as to how to do it.
The Script randomly pics a movie clip and tells it to play. Now I need the picture in the movie clip to be randomly picked from a group of 10 pics in the library. I have no Idea how to do this within the context of this script.
Please help and thanks
timerID = setInterval(controlPic, 5000);
function controlPic() {
mcA = new Array();
//put your movieclip names in here
mcA = [pic1, pic2, pic3, pic4, pic5, pic6, pic7];
for (ivar=0; ivar<mcA.length; ivar++) {
mcA[ivar].stop();
}
playmc();
function playmc() {
clearInterval(restartI);
ind = Math.floor(Math.random()*7);
mcA[ind].play();
}
}
Math.random But Bot 100% Random :-)
Hi,
With the help of Math.random(), I'm loading random jpg's every 10 seconds (from a folder with 300 jpg's).
Is there a way to make sure that every jpg has been loaded before one is loaded a second time?
I managed to make sure no jpg is loaded 2 times in a row, but I need to store each chosen number and compare the new number with all those stored ones.
Random, Random Animation :)
Hi all
im trying to jump to a random animation (label) with a random delay between the jumps.
here is the code that is in the first frame
Code:
Pause = setInterval(blitz, random(30000)+15000);
function blitz() {
var aLabels:Array = ["one","two","three","four"];
tmpNum=Math.round(Math.random()*4);
trace(tmpNum);
gotoAndStop(aLabels[tmpNum-1]);
}
but ... its not working ... the only thing that happens is that the first animation is looping ... im using flash 8.
anyone got a hint for me what im missing?
Thanx
Tim
Random Numbers Not Random
I'm trying to get a random number between 1 and 4 with this code:
Code:
e = Math.floor(Math.random()*4+1);
...but I only get random numbers between 1 and 3.
When I do it with:
Code:
e = Math.floor(Math.random()*10+1);
...it works pretty well - I get random numbers between 1 and 10 - not perfectly random, but good enough.
Does anybody know why?
|