Flash Random Playing
I need to know how to run a small piece of media at random times; however, i cannot. Could anyone help?
FlashKit > Flash Help > Flash ActionScript
Posted on: 06-11-2004, 08:52 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
[CS3] Flash Help Playing Random Movieclips
I desperately need help!
What I want to do:
I want a different movie clip to play each time the swf file is loaded. And after the movieclip has finished playing, I would like another random movieclip to start.
What I have:
I have four layers all on the first frame, one actionscript layer the other three contain a movieclip each. Could this be the problem?
I have placed this actionscript into the actionscript layer:
Quote:
var clips:Array = ["Paul_mc", "Gary_mc", "Ama_mc"];
playRandomMC();
function playRandomMC() {
var index:Number = Math.floor(Math.random()*clips.length);
for (var i:Number = 0; i<clips.length; i++) {
var mc:MovieClip = _root[clips[i]];
if (i == index) {
mc._visible = true;
mc.play();
} else {
mc._visible = false;
mc.stop();
}
}
}
However this isn't working, anyone know how I should amend my actionscript? Or is there another way of doing this without actionscript?
Thanks for any help
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 Playing Swf
hi everybody !!
i hope somebody can help me
this is my problem
i have a main movie on level0 and 4 more movies(swf)
which contain some music loops
now i loaded all 4 movies on the main movie...so far so good
now i want to play each movie randomly but avoiding to reapeat the same movie within the four sequence
eg play
1342 then another random sequence like 3241 and so on
notice that the digits inside the sequence never repeats
i don't want something like 1123 or 3321 or 4341
hope i am clear enough
please hope a hopeless newbie
ciao magnetos
Random Playing
hi
what would be the easiest way of making a movie clip play repeatedly, but at random intervals?
Playing Random MCs
Hey,
I have 6 MCs. How can I have them appear randomely on the stage?
Thanks.
Playing Random FLV's
Help Needed!
I believe this is the code required to play a FLV dynamically but how do I make it play random videos - for instance - video1.flv, video2.flv, etc?
on (release) {
var netConn:NetConnection = new NetConnection();
netConn.connect(null);
var netStream:NetStream = new NetStream(netConn);
netStream.onStatus = function(infoObject) {
status.text += "Status (NetStream)"+newline;
status.text += "Level: "+infoObject.level+newline;
status.text += "Code: "+infoObject.code+newline;
};
my_video.attachVideo(netStream);
netStream.setBufferTime(5);
netStream.play("04_56k.flv"); ---> include the random function here?
}
Thanks for anyhelp!
Matthew
Random Movie Playing
I have 4 movies the will be at the beganning of a flash app. I want them to play at random when play is clicked. Is there any way to do that?
Random For Playing A Frame
Hi I think this is a very simple problem but I cannot figure it out.
I have a 4 frame movie on frame 2 there's a blue circle on frame 3 there's a green circle and on frame 4 there's a red circle.
I want my movie to play one of the three different frames each time you run it. I'm using the following actions on frame 1
frame = 1+random(2);
gotoAndPlay (frame);
Could someone help me?
Playing Random Frames
Argh. I used to have the string of code which plays random frames of a movie clip, but I lost it. And I can't remember what it was.
Help please...
Do any of you know this action script code offhand?
Playing Random Scenes
I am trying to set up a quiz that will ask 10 questions each time it is played, but will draw those questions from a pool of a hundred or so. What is the simplest way of having the program 1) go to a random question picked out of a pool, 2) only picking that question once per quiz.
I have literally years of experience with Director and literally minutes of experience with Flash, so I understand the concepts but have no idea how to carry them out in this program. Any help is greatly appreciated.
Playing A Random Scene
I am trying to figure out how to randomly play a scene from a list of scenes...
here is the code I am using which doesnt seem to work:
fileList = new Array();
fileList[1] = "scene1";
fileList[2] = "scene2";
fileList[3] = "scene3";
randomNum = random(3);
sChoice = fileList[randomNum];
gotoAndPlay (" + sChoice + ", 1);
any help would be appritiated...
thanks
Random Playing Cards?
Hi,
My project: There is a deck of playing cards and when you press a key, then one randomly appears/flips over on the screen. Then another button can make it disapear again. Is this possible?
Any help would be appreciated since I sux0r at actionscripting.
Thanks!
Playing Random Labels Or MC's
Is it possible to play random frames on the timeline using labels?
Also how to I load a random movie clip at the same time?
I've got 6 character sequences that I need to play randomly. At the same time a random speech bubble appear. Any help is appreciated.
Random Moviclips Playing
ok. I put this up in Flash General and nobody got it, and it seems quite simple so somebody here should be able to help...I hope
I have four identical mc's on stage, called bar1. bar2, bar3 and bar four. They have a stop on their first frame, a simple animation and then a gotoAndStop(1); on the last frame.
Also on stage is an activator clip. It is to keyframes, on the first frame is the script
test = random(5)
_root.bar(test).play();
Mc's Playing At Random Times
I want the buttons in my movie to flash or glow at random times. After i make an mc to create this effect, what actionscript should i use so that these mc's play at random times? Any help would be greatly appreciated.
Playing Random Movies.
I have created a banner and there is an intro movie.
now after this intro movie, I have created 5 different movie clips that are placed on there individual frames (frame# 71-75)
Now I was wondering if it were possible to play the intro movie then have it randomly play one of the frames 71-75, after each movie clip has been completed , it can either go back to playing the intro movie, or just play a different movie clip on the the other frames.
This is the code I have been trying to work with but everytime it just plays frame 75 and after that movie clip is copleted it just stops and doenst go play the other movie clips.
at the end of each movie clip I have this
gtoAndPlay(_root);
.. so they return to the beginning of the main timeline.
The code to jump to a random frame between 71 and 75 is :
randomFrame = Math.floor(Math.random() * 75 + 71);
gotoAndStop(randomFrame);
can someone help me and tell me what I am doing wrong, that would be greatly appreciated.
Playing A Random Frame?
hi, im using flash mx, and i was wondering how to make a button play a random frame out of a selection? e.g. playing frame 6 or frame 8
Playing Random Movies?
I tried to search the above, but the search function seems to be dead. Otherwise I am sure this has been asked and answered many time before!
Can anyone help me with having a button that onclick loads a random swf? I used to be able to do it in Flash 5, but that was years ago and I can't remember for the life of me.
Much thanks in advance!
Playing A Random MC On Click
I was wondering if someone could give me a helping hand.
I'm doing a navigation bar and on part of the bar each time you click on this part of the bar it will play one of 5 clips.
Now i made the button for the on(release) so i have it playing a MC and in the MC it has one of the random events on frames 1-5 (so each frame is it's own movie)
How would i make the button that tells the MC to play 1 of the 5 frames but making the frame selection random?
Thank you, (if there is a tut for this just supply me a link, if you know the code it would be much appreciated as well)
Playing .wavs At Random
Hello, what I want to accomplish is when a button is pressed, Flash finds a random .wav file on my server, and plays it.
ranvar=random(50);
ranvar2=Math.round("0"ranvar);
????dontKnowTheCodeToSoundPlay("http://theinterpet.nfshost.com/sound/chicken0"ranvar2);
I also want to mark that number not to be played again until it has cycled through all of the others. I know this is semi-complicated, how would I go about it?
Playing Random Keyframes
Hi,
I'm relatively new at this Flash business, and I'm trying my hand at a variation on the Magic 8-Ball game in Flash MX.
Basically I want the Magic 8-Ball questions to incorporate not just random text, but images and sounds as well.
Seemed to me the easiest way to do this was to create each separate answer as a different "movie clip" - then I created each movie clip on a separate keyframe - so, for example, Answer 1 plays between keyframes 2 and 22, Answer 2 plays on Keyframe 23, etc.
So, basically where I'm at is finding the best way to have the file pull a random keyframe from a list that i provide. So, pull a random keyframe from 2, 23, 24, 32, etc.
Or, if there is a better way to approach this altogether, I'd be interested in hearing that as well.
Thanks a lot!
Jason
Playing Random Frames
I'm trying to make make my quiz game play ramdom frames and not play the same frame twice.
I found this on another forum but Im not sure how I can use it the way im doing things
this is written on the first frame,
-----------------------------------------------
Code:
[as:1:e3373511da]mc.onRelease = function()
{
this._parent.random_frame();
}
var frames = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 ]
function random_frame()
{
var c = frames.splice(random(frames.length), 1)
mc.gotoAndStop(c)
trace(frames.length)
}
[/as:1:e3373511da]
My que to send the playhead to the next frame is at the end of an animation on the timeline.
Would I just use write the array and splice var then call it at the end of my animation? like
-------------------------------------------------
on frame one
-------------------------------------------------
Code:
var frames = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 ];
function random_frame();
var c = frames.splice(random(frames.length), 1);
-------------------------------------------------
on my animation timeline que
-------------------------------------------------
Code:
_root.gotoAndPlay(c);
-------------------------------------------------
am I on the right track?
any help would be much appreciated.
Mark
Playing At Random Intervals...
hello all.
on my timeline there are 3 stops.
at each stop i would like to set some actionscript that says play at random time intervals. so the play head pauses at the stop(); for the random time before it goes to the next.
random = time between 10seconds and 30seconds.
play on random
any help is appreciated.
Playing Two Mc In Random Order?
Hi friends,
I have 2 mc in one fla. I want to play them randomly when I open the flash..
I couldnt do..
I used this codes but nothing happens
I add codes to first layer.
I add them to different layers but same frame.
var myArray = new Array();
var shownArray = new Array();
var myRandom:Number;
var currentText:String;
var prevText:String;
myArray = ["mov_0","mov_1"];
shownArray = [];
function doRandom():Void{
if(myArray.length == 0){
myArray = shownArray;
shownArray = [];
};
myRandom = random(myArray.length);
txt.text = myArray[myRandom];
play();
shownArray.push(myArray[myRandom]);
trace("myArray : "+myArray);
trace("shownArray : "+shownArray)
myArray.splice(myRandom, 1);
};
var myInterval:Number = setInterval(this,'doRandom',2000);
stop();
[CS3] Random Frame Playing
I'm quite new to flash and am having a big issue trying to do a relatively simple function. Basically I've created a flash banner that holds many different adverts, and i want the banner to randomly select each advert (so they don't play in a set order).
At the moment each advert is a separate movie clip (as they fade in from white and back out to white), with each of these separate movie clips on a different frame on the main timeline.
So basically i want flash to select a movie clip (an advert), play it through, then randomly select another movie clip (another advert), and repeat this process continually!
Please help! thanks!
Sounds Playing At Random
Can someone tell me why my sounds are randomly playing in the wrong spot? i put a sound in a movie clip and for some reason it also plays on the main timeline when i hit a specific button. Somebody pls help!
Playing A Random Movie
Hiya Peeps,
I'm trying to play random movies, (so far I only have 2 movies which I want to got and stop at random frames (1-3).
Here's what I've got so far:
//Array with names of my movies
var myArrayName = new Array();
myArrayName[1] = "blondman";
myArrayName[2] = "tallgirl";
//Random movie
x = Math.ceil(Math.random() * 2)
//Random frame
y = Math.ceil(Math.random() * 3)
character = myArrayName[x];
_root.character.speech.gotoAndStop(2);
This doesn't work please help! I think the problem is with the word character - I think I need to do something to it - use eval() somehow?
Thank you,
Jk
Playing Random Frames
I have a password field and a enter button. There are certain passwords that are specified in order to get to the secure area. I want the user to be able to click a get password button and one of the passwords is randomly displayed in a popup window. That is where the problem is. How do I randomly select frames in a moviclip by clicking a button?
Playing MC At Random Intervals
Hi, can anyone tell me how to code a movie clip to play at random times (i.e. wait five minutes and then pick a random number of minutes and play again). I scanned through the tutorials but there's a lot to go through and I'm not sure what to look at.
Playing Random Movies
Hi,
I was looking for tutorials on this but each script, and tutorial didnt work for me. I've got three movieClips on my main stage, movie1, movie2, and movie3 (its the instance too). Very predictable.
Not on load but rather I'd like each one to play in a random sequence. Maybe movie1 plays first, followed by movie3, not 1, 2, 3.
I tired this:
num = random(3)+1;
movie = "movie" + num;
movie.gotoAndPlay(2);
I've got a stop(); on the first frame inside each movie clip.
Thanks
Edited: 11/19/2008 at 05:26:52 AM by graham howe
Playing Random Flv Files
Hi all,
Im really struggling with this, what it is I am trying to make something in flash that will load a random flv when a web page is refreshed, I have done it using swf files befroe but I need it to do the same with flv.
can anyone point me in the direction as to where I amy find a good tutorial for doing this.
Thanx in advance
Rob
Random Playing Of Movies
Hi,
I'm trying out this example. I have 3 movie clips on stage with instance names m1, m2 and m3. They all are animated and have a stop() action in the 1st frame, now i have a function that picks up movie clips on the stage randomly and plays their 2nd frame. This is the code i've written for it.
Code:
function randomPlay(){
var i = random(4)
if(i==0){
} else{
m(i).gotoAndPlay(2);
}
}
setInterval(randomPlay, 5000);
When i run the code, nothing works, can anyone tell me whats wrong or suggest a better method ?
Code For Playing Random Scenes
i made an interface where when you press a button, i would like it to play random scene. I have 34 scenes, the first being the starting point (where the button is clicked) and i want it to play 2-34 randomly. i named them "scene1, scene2..." and so on. do i have to declare the specific names of those scenes (make an array) and then call them in the code?
i tried making a variable that uses the random() command ("scene"+variable,1), but anything in the area specifying the scene you want to play has to be quotes as we all know, so it doesn't recognize something in that region that isn't, and it just plays the scene name that is specified in the quotes.
stressing here...any help would be appreciated. let me know if you need more info.
thanks guys!!!
saxw
Random Playing Of Movie Clip Help Pls
Hi all. I have a question about how to randomly play a movie clip. Here is what am trying to do. I have a background that looks like a circut board. I want an electric pulse to run on a guide and follow one of the lines in the board. The MC works fine except I would like the pulse to be random. I think it just looping looks stupid. Please any help would be greatly appreciated.
Thanks for reading.
Tom
Playing A Random Movie Clip
Is there a way to go to and play a random frame or load a random movie clip.
What I am trying to do is place the actions on a button so on release it will choose a random movie clip and play it.
could I do this using an array?
please help I have a deadline.
Random Sounds Keep Playing When They Shouldn't...
I've come accross a bizarre problem. I've been making a stand alone projector and the movie is pretty large packed with images, animation and sound (about 100Mb but it is for a CD Rom presentation not web based!)
I've been creating sound movies which are in various scenes, and these movies just contain the individual sound clips (background sounds which go along with the imagery) - I hope you're still with me!
The problem is that every now and again certain sounds will trigger where they are not supposed to - for example, when you click the button to goto a scene inside a church, the sound movie "footsteps" plays as it should, but the seaside sample is also triggered which is nothing to do with that part of the story! Very strange.
I was just wondering if anyone else has come across this sort of thing, and if so, how did you get round it?
Any advice or help very much appreciated!
Rob.
Playing Random Sounds From The Library
Hi, I'm trying to pull out and then play random sounds from the library.
Here's my code (don't laught I'm sort of a noob) :s
piano1 = new Sound();
piano2 = new Sound();
piano3 = new Sound();
piano4 = new Sound();
//
piano1.attachSound("piano1");
piano2.attachSound("piano2");
piano3.attachSound("piano3");
piano4.attachSound("piano4");
//
_root.onMouseDown = function() {
piano+random(4).start(0, 1);
};
Ok. The problem is at the,
piano+random(4).start(0,1);
The code works when I take out the random...
But I need it to play randomly.
What am I doing wrong?
Thanx!
Playing Movieclips In A Random Order
Hey guys.
I am trying to develop a little presentation.
Even though I have been using flash for a while, my actionscripting leaves a lot to be desired.
My tweening is good though, so I wondered if anybody could help me put together the following description?:
Firstly, I have is a preloader followed by an 'intro' movie clip. Should this even be a movie clip? It only needs to play once. Should it be in its own scene?
Secondly, I have designed six movie clips that I need to play in a random order after the intro.
Thirdly, I have an 'outro' movie clip. Should this be a movie clip or have its own scene?
I'm sure this project invloves some pretty basic actionscripting, its just a shame it isn't basic enough for me!
I appreciate any help.
Thanks guys!
Text And Playing Random Messages...?
Hi
I am looking for a way to produce a flash banner, with small tag lines of text that float across the movie.
I want to use upto 30 tag lines of text, that play randomly...
Now although I can do this with tweening, the film will be big in KB, what I would like is some action script guidance as to how I could pre programme the lines to play....??
Any ideas???
Your help is appreciated
ZA
Playing Random Movieclips From Buttons
Hi everyone
I am in the process of making a question and answer game in MX2004 where upon typing in the question and hitting the submit button an animated character will randomly give a yes or no answer.I am hoping to find a way where on mouse up I can randomly play one of up to 10 'yes' or 'no' movieclips.These movieclips will have sound.I suppose it is similar to a talking magic eightball but I have been unable to find any useful tutorials.Any ideas would be appreciated!
.mp3 Starts Playing In Random Place
i need a code so when my viewers enter my site a mp3 will start playing music in a random place my .mp3 file is 3hrs long and it is called mp3.mp3
here is my code can you plz plz fix it thank you so much
Code:
var mySound:Sound = new Sound();
mySound.loadSound("mp3.mp3", true);
mySound.start(soundGoTo.Math.random());
i found this off a tut of a mp3 scrub and edited it
thanks
Random Swf-s Playing On Internet Site
Hi
I am making a web page and somewhere on page i will add small monitor/player for swf-s that i created. Like porfolio or something. Well since i am still a flash beginner i would like to ask what is the best way to do this. Loading swf-s via xml or array or something else? What would be the best approach for this?
tnx in advance for pointing me in right direction.
Luka
Playing A Random Movie Clip
Hello everyone,
I am a goofy science type, new to flash, though used to using lingo in Director.
I have a set of 9 movie clips. One of them is showing something that happens most of the time (like 99% of the time in the real world, so probably 90% in my animation), so I will just leave it looping continuously in my animation. I would like one of the remaining eight to appear every once in a while, and which one is played should be random. I would like to be able to recycle the movie clips used, so that they can still be part of the random grouping, but I would like to pause the clip after it runs through that one time.
I found out that I cannot stop a movie clip from within using its instance name.stop(), though I was able to put in a frame label named "pause", and stop it externally using name.gotoAndStop("pause"). However, that path seems to lead me into troubles with the whole randomness thing, since I have to name the movie clip each time.
If anyone has any thoughts on the matter, I would appreciate your time. (So would my wife, who claims that I am obsessing about why I can't get the d$&%^! thing to work)
Thank you, BobR
Playing Random Movies On Load.
Hello all. I have read through a lot of the forum, though not all, so I am sorry if this is a repeat question, but what I would like to do is load random movies into a SWF on load. So when my swf loads, I would like 1 of 19 movies to reandomly begin playing within a specific area. Anyw help with this would be greatly appreciated. I have just gotten Flash 8, and there are a lot of new techniques that I have not used before. Thanks so much for your time!
Peter
Playing A Random Embedded Sound
I'd like to play a random embedded MP3, but my efforts so far have been unsuccessful:
Code:
//embed sounds
[Embed(source="assets/sound/1.mp3")]
private static var sfxLibrary1:Class;
[Embed(source="assets/sound/2.mp3")]
private static var sfxLibrary2:Class;
[Embed(source="assets/sound/3.mp3")]
private static var sfxLibrary3:Class;
// other sounds embedded here...
// ---- code removed for brevity ------ //
//create and play a random sound effect
var sfxNo:Number = Math.floor( Math.random( ) * 3 ) + 1;
var ClassReference:Class = getDefinitionByName("sfxLibrary"+String(sfxNo)) as Class;
var sfx:Sound = Sound(new ClassReference());
sfx.play();
When debugging, the thread is suspended with "ReferenceError:Error #1065: Variable sfxLibrary3 is not defined"
Can anyone see where I'm going wrong, or think of a better way of doing it?
Playing 2 Movies In Random Order
Hi friends,
I created two flashes (also two swf).
I want to add these flashes to two seperate frames as movie.
And I want them to play randomly when I open the flash on first time.
Ex. when I enter the page first flash will appear.
two hours later, when I enter the page second flash will appear..
how can ı do this in one swf..
thanks
Playing A Random Sound Effect
Hello everyone,
I am very new to AS3, but I am learning quickly and it has all been very fun. Just a quick question that I'm sure is simple but is beyond me at this point.
I am trying to develop a simple game. What I want to accomplish is when you click on the characters head, a different sound effect (from a list of 5 or so) is played. I've gotten it to play one sound by using the following code:
Code:
// play sound on click
var sound:MonkeySounds = new MonkeySounds;
var channel:SoundChannel = sound.play();
All of that is wrapped inside a function with an eventListener that responds to MOUSE_CLICK, which works fine. How would I get it to play a random sound effect from, say a list of 5 or so sounds? I learned the method above from this tutorial: http://blip.tv/file/341009
Any help is appreciated. Also, would it be beneficial to put this into a class? I'm not really sure how to accomplish that either, but I am going to need random sound effects down the line in this project so that may be of use.
Thank you all!
Random Playing Movies On Frame 1
I have 5 movies on my main timeline on Frame 1. Thats all the frames I use for the main timeline.
Each of the 5 movie are of a fish jumping out.
All the fish movies has a stop on Frame 1 so they will not animate unless theres a command to play them, for eg. _root.fish1.gotoAndPlay(2);
_root.fish2.gotoAndPlay(2);
_root.fish3.gotoAndPlay(2);
and so on...
What I would like to do, is maybe place a script on the main timeline, frame 1 that will randomly get fish movies 1-5 to animate in random like a lake filled with fish randomly jumping out of a lake.
I would also like to be able to have control of how many fishes will randomly play in random in the script by just changing the value maybe? Like maybe 2 or 3 fishes at a time.
How can I do this?
|