Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Can I Pick A Random Frame In An Swf File?



I have a swf file that say on frame 1, I'd like to randomly have the movie jump to either frame 2, 3, or 4. Is that possible, and how would that be accomplished. Thanks for your help.
chad



FlashKit > Flash Help > Flash ActionScript
Posted on: 02-05-2002, 06:40 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

How To Use Random Function To Pick A Frame
hi all if i have a movie clip with 11 frames and there is a blank frame at the start with stop action


what is the code if i want to pick a random frame from frame 2 to 11
but any frame ((((( were piked we can not pick it a gain ))


this is the trick :)

S.O.S. (random Pick)
i am trying to use a random code that picks between MC1 and MC 2 at random intervals but NEVER picks the two together. The way i set it up is:
i have two main movie clips on the scene ("mainMC and engine")
One clip is the engine with the actionscript, and the second contains the two random MCs. ("MC1 and MC2")
The main movie clip designed as an engine has 3 actionscript frames in it.
• The first frame within this engine MC has the script:
seconds_low = 2;
seconds_high = 8;
rand = Math.round(Math.random()*seconds_high)+seconds_low ;
start_time = getTimer()/1000; move2 = math.round(math.random());

Random Pick Of MC
Hi,

I want a script or action that randomly pick a movieclip out of a folder of mc's, how can i do that?

Pick Random Value In Array And...
Hello

How do I make a random choice in an array, and when a certain object is picked, the next time it can't be picked, only after all the objects in the array have beem picked. For example:


Code:
cities = new Array();
cities = ["New York", "London", "Rio de Janeiro"];


Say that in the first time, the function randomly picks index number 1 ("London"). In the second time, it can only pick either indexes 0 or 2. If it randomly picks 0 ("New York"), the next time it can only pick index 2... when it finally picks index 2, the function sees that all the possible indexes have already been picked, then it starts over, meaning that in the fourth time you can pick any of the three indexes.

I have tried to do this using loops, using length, splice, slice, everything, put I think I am too slow to figure out the problem! Please help meeeeeeee!!! :confuse:

Best regards
Daniel

Random Array Pick
Quick question.
Can someone please tell me how to randomly pick an item from an array.
So if the array was called "numbers", how to randomly pick an item from the numbers array and store it in a variable. thanks

Pick A Set Of Random Numbers
I have 100 numbers (1 through 100), and want to pick 10 random numbers from this set. Normally I would do

for (i=1; i<=10; i++) {
myVar = random(100)+1;
trace(myVar);
}

but this time I need all the random numbers to be different (thay can't repeat). How would you approach it?

-Bartosz
www.BGPORTFOLIO.com

Pick Random From An Array
Hi!

I have an array of mc:s:
pictureMC = [mc1, mc2, ... , mc60]

they're all small pictures in a movie .. and I want them, from being invisible to light up in a random manner on by on or more don't really matter.. so how do I pick them up from a random function and light them.

Maybe the lit ones should get true or something so they' d get exluded from whatever function.. man I'm stuck!!

Button Pick Random Mc ? But With Timedelay ?
Im making a litte game and I need some code on a button that when pushed down random choose betwen 3 mc´s. But when you push the button there have to be some time delay before the random choosen mc appear or starts....

I have attached a fla.....not the one from my game, is there anyone who knows what code you can put on the button so when pushed wait betwen 5 and 10 sec. (I mean sometimes it starts after 5 sec. and sometimes 7 sec. etc)

The fla file can random choose betwen 3 mc´s, but how to make the code that makes some timedelay ???

Please ???

MX - Button Pick Random Mc ? But With Timedelay ?
Im making a litte game and I need some code on a button that when pushed down random choose betwen 3 mc´s. But when you push the button there have to be some time delay before the random choosen mc appear or starts....

I have attached a fla.....not the one from my game, is there anyone who knows what code you can put on the button so when pushed wait betwen 5 and 10 sec. (I mean sometimes it starts after 5 sec. and sometimes 7 sec. etc)

The fla file can random choose betwen 3 mc´s, but how to make the code that makes some timedelay ???

Please ???

Pick Random Swf And Load To Movieclip
Hey dudes.

I have this script on a frame which loads .swfs into clips:
Code:
stop();

_root.whatLoad = "middle";
mtClipLeft_mc.loadMovie("homepageLeft.swf","homepageLeft");
mtClipRight_mc.loadMovie("homepageRight.swf","homepageRight");
Except I would like to change the homepageLeft.swf bit into a random bit.

What I mean is:

I will make a folder called homepageleft and inside this folder I will have .swfs called "homepageLeft01.swf", "homepageLeft02.swf" etc.

I want the above script to be able to pick a random number based on the number of possible .swfs there are to choose from (say 5) and then add that number to the end of "homepageLeft" and then add ".swf" onto the end... does that make sense / is that possible? Thanks for any help.

Peace


edit. just re-read and it doesnt make a great deal of sense huh?

to clarify.

I want movies to load on the left hand side of my homepage. This works fine so far as i only have one movie "homepageLeft.swf". Groovy.

The next step is to have a selection of possible movies to load and to pick a random one and load that. They will all be the same dimesions but rather large - hence the separate movies (each will have a preloader built in).

Thanks again for any help

Pick Random Images Without Duplicates
Hi,

I'm trying to write some script that pulls images from an xml file into an array, and then randomly picks out 5 of those images without selecting any duplicates, this is the code i have so far, but i'm not too sure how to tackle the duplicates issue? If anyone could help me out i'd be most grateful


mugShots = new Object();
mugShots.length = 0;

myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(success) {

total = myXML.firstChild.childNodes.length;
path = myXML.firstChild.firstChild
imagePath = "http://www.monstermob.com/images/reskin/mugshots/";

for(i=0; i<total; i++){
item = new Object()
item.id = path.attributes.id;
item.src = path.attributes.src;
mugShots[i] = item;
delete item
mugShots.length++;
path = path.nextSibling;
}
trace(mugShots.length)

for (i=0; i<5; i++){
k = Math.floor(Math.random()*total);
_root["item"+i] = mugShots[k].src
_root["id"+i] = mugShots[k].id
trace(_root["item"+i])
trace(_root["id"+i])
}
_root.picture1.jpg_holder1.loadMovie(imagePath+_ro ot["item1"]);
_root.picture1.jpg_holder2.loadMovie(imagePath+_ro ot["item2"]);
_root.picture1.jpg_holder3.loadMovie(imagePath+_ro ot["item3"]);
_root.picture1.jpg_holder4.loadMovie(imagePath+_ro ot["item4"]);

}

myXML.load("http://www.monstermob.com/members.xml")


Thanks

Pick Random Images Without Duplicates
Hi,

I'm trying to write some script that pulls images from an xml file into an array, and then randomly picks out 5 of those images without selecting any duplicates, this is the code i have so far, but i'm not too sure how to tackle the duplicates issue? If anyone could help me out i'd be most grateful


mugShots = new Object();
mugShots.length = 0;

myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(success) {

total = myXML.firstChild.childNodes.length;
path = myXML.firstChild.firstChild
imagePath = "http://www.monstermob.com/images/reskin/mugshots/";

for(i=0; i<total; i++){
item = new Object()
item.id = path.attributes.id;
item.src = path.attributes.src;
mugShots[i] = item;
delete item
mugShots.length++;
path = path.nextSibling;
}
trace(mugShots.length)

for (i=0; i<5; i++){
k = Math.floor(Math.random()*total);
_root["item"+i] = mugShots[k].src
_root["id"+i] = mugShots[k].id
trace(_root["item"+i])
trace(_root["id"+i])
}
_root.picture1.jpg_holder1.loadMovie(imagePath+_ro ot["item1"]);
_root.picture1.jpg_holder2.loadMovie(imagePath+_ro ot["item2"]);
_root.picture1.jpg_holder3.loadMovie(imagePath+_ro ot["item3"]);
_root.picture1.jpg_holder4.loadMovie(imagePath+_ro ot["item4"]);

}

myXML.load("http://www.monstermob.com/members.xml")


Thanks

Button Pick Random Mc ? But With Timedelay ?
Im making a litte game and I need some code on a button that when pushed down random choose betwen 3 mc´s. But when you push the button there have to be some time delay before the random choosen mc appear or starts....

is there anyone who knows what code you can put on the button so when pushed wait betwen 5 and 10 sec. (I mean sometimes it starts after 5 sec. and sometimes 7 sec. etc)


I have made the fla file to random choose betwen 3 mc´s,

but how to make the code that makes some timedelay ???

Please ???

Pick A Random Image And Ask A Question - Please Help
Hi people,

My first time here and i was wondering if you could help me.

I am trying to build a simple flash game and was wondering if you flash guru's could help me.

I would like to be able to pick 1 of 8 images in the library at random and display it on the canvas. Once the image has been displayed i would like 3 symbols to be displayed underneath. 1 is correct and 2 are in-correct.

Get the symbol right first time and it's worth 3 points get it right second time 2 points and 3rd time 1 point. So the less accurate you are with your answer the less points you get.

Once the right symbol has been chosen it adds the points to a score total sheet and then selects another random image out of the remaining 7 images.

Once all the images have been used up it gives your final score! :)

Of course i appreciate that you people arnt going to give me a finished game but i would appreciate some pointers to help me build it myself.

I'm stuck on the random images selection from library expecially and also that need to take away answered questions from the images list. Any help on this would be fantastic.


Thank you in advance :)

How To Pick Random Unique Elements Out Of An Array
I have an array of sprites. I'm using the following code to apply an animation to a randomly chosen sprite in my array:


Code:
var i : int = Math.floor(Math.random() * tempTileArray.length);
var child : Tile = tempTileArray[i];
child.bonusTileEffect();
My question is how do grab more than one random element from my array? I would like to apply my animation to x random sprites in my array.

Appreciate any help you can offer.

Combobox To Pick Frame
i want to have a combo-box with different options. Say the options are 1, 2, and 3. If you pick 3 and then press an ok button it will take you to frame 3. The same basic consept for the others.

Why Won't Flash Pick Up Meta Data From FLV File?
Hello,

I've built up a package around Lee Brimelow's custom video player using a bit of his tutorial in AS 2.0 and the update in AS3.0. After some tweaking I've managed to get most of the functions working.

However, it would appear that although the old AS2.0 code would pick meta data in the clip such as duration, I can't pick up the data using this code.

Can anyone tell me what I'm doing wrong?

Cheers,


Code:

stop();

var videoInterval = setInterval(videoStatus, 100);
var amoundLoaded:Number;
var duration:Number;
var playTime:Number

mainBtn.addEventListener (MouseEvent.CLICK, returnHome);
function returnHome (e:MouseEvent)
{
   ns.pause();
   gotoAndStop("main");
}



profilesMC.visible = false;



    profilesMC.fence.arthurMitchell.alpha =0;
var nc:NetConnection = new NetConnection();//this establishes a connection to the internet
nc.connect(null);//this tells Flash that this isn't a Flash Communication Server project
var pauseVid:Boolean = new Boolean(); //setting up the play/pause control
pauseVid = false;//initial parameter is that video is not initially paused.


var ns:NetStream = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, onStatusEvent);



var meta:Object = new Object();
meta:onMetaData = function (meta:Object)
{
   trace(meta.duration);
}

function onStatusEvent(stat:Object):void
{
   if (meta.code == "NetStream.Buffer.Full") {
      bufferClip.visible = false;
   }
   if (meta.code == "NetStream.Buffer.Empty") {
      bufferClip.visible = true;
   }
   
   trace(stat.info.code);
   
}


ns.client = meta;

theVideo.attachNetStream(ns);

ns.play(vidLink);


rewindBtn.addEventListener (MouseEvent.MOUSE_DOWN, rewindVideo);



function rewindVideo (e:Event){
ns.seek(0);
};

playBtn.addEventListener (MouseEvent.MOUSE_DOWN, playPauseVideo);

function playPauseVideo (e:Event):void
{
if (pauseVid == false){
pauseVid = true;
trace ("pauseVid = true");
playTime = ns.time;
      ns.pause();
}
else{
   pauseVid = false;
   ns.resume();
   
   
}

}
   
   function videoStatus() {
   amountLoaded = ns.bytesLoaded/ns.bytesTotal;
   loader.loadbar.width = amountLoaded*211.9;
   //211.9 px is the width of the loaderbar
   loader.scrub.x = ns.time/duration*211.9;
}

Movie Go To Random Frame Flash MX (Strange Problem With A Frame Showing As Blank)
I'm building a site for my fathers company and as part of the header I'm trying to get a movie to decide a random frame to go to so it plays a random animation at the top of each page.

I am using this script (which im not sure is right to make it do this)

play();
what_number = Number(random(3)+1);
gotoAndStop(_root.what_number);

It seems to work but the problem is there are 3 frames, 2 show up fine in random mode but it seems when the other is going to be shown i just get a blank frame instead with just the bg colour showing, ive spent hours trying to work out whats going on but I have no idea.

The site can be viewed at http://www.andrew-winchester.com/pip After you navigate from the index page the smaller random header appears and should show either of the 3 animations from the main header on the index.

Here is a link to the .fla for the smaller header file if that helps http://www.andrew-winchester.com/pip/header.fla


This is really driving me crazy, there must be some simple solution that I am overlooking or some silly mistake ive made ?

Thanks for anyone that can solve it !

How To Remove A Frame From A Goto Random Frame Set?
I'm building myself a simple set of Flash Cards for school and the setup I have is to goto a random frame where ActionScript loads in a question I've put on that frame. I'm using variables to keep score of the ones I get right and wrong.

What I want to be able to do is when I get an answer right and Flash goes to the next frame randomly, to have this current frame REMOVED from the options of frames it can go to. This way, it won't repeat any questions I've answered right.

Random Frame Or MC, But Ignore Current Frame
Hi, I've got this:


ActionScript Code:
gotoAndStop(random(5)+1);//orthis["btn"+(random(5)+1)].onPress();

But I'm having troubles telling it to ignore the current frame or MC its on. I only need it to randomise to something else... not what its already on.

Any ideas? perhaps it needs to set a few variables, then do a quick function check before actually randomising?

Thanks for your time.

Mark

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

Random..er..Random Frame
This isnt simply just a random frame question

My simple script is as follows,

ActionScript Code:
if (whatever) {    _root.somemovieclip.gotoAndStop(random(1+10));

It jumps into a movie clip and goes to a random frame between 1 and 10.

What I need it to do, is (for example) go into that movie clip and play either frame 3 6 or 9. Disregarding every other frame not specified.

Somebody pleeease help me on this one, I'm so close to getting what I need to do done

Thanks!

-Paul

Random..er..Random Frame
This isnt simply just a random frame question

My simple script is as follows,

ActionScript Code:
if (whatever) {    _root.somemovieclip.gotoAndStop(random(1+10));

It jumps into a movie clip and goes to a random frame between 1 and 10.

What I need it to do, is (for example) go into that movie clip and play either frame 3 6 or 9. Disregarding every other frame not specified.

Somebody pleeease help me on this one, I'm so close to getting what I need to do done

Thanks!

-Paul

Pick Me, ME, ME, ME
Really need a low down on creating a basic website working on Level. The jpeg images I'm using for background are far to large to have all loading In on one flash movie. So I though it be best to have all the backgrounds load in on Level1.

Bottom line - I'm having a hard time working this baby out!!

this is a link to the way Im doing it which works offline though not online, Preloaders just goes to blank.
http://www.flashkit.com/board/showth...hreadid=504323

...........................
Could you maybe explain how you would create a website on levels, In baby language please

Cheers

Random Frame
Its probably really simple, but anyway
I just need a button that will jump to a different frame each time. So say a main page and when you click the buton it will advance to a random destination along the timeline.

It would e well wicked if you could help me.

Random Frame?
Anyone know how to make a movie play any frames at random?

Thanks

Random Frame
Random Frame? Is there a thing...

Is it possible to get a Random Frame with in a Scene?

say like on Frame 1? Use a Random Number then set that number to a frame? To go to one of the other frames in that scene.

Going To A Random Frame
Ok, I have tried everything I can think of and nothing seems to work. Here is the situation: in my movie i want to play for about 35 frames and then I want to go to a random frame, but not just any random frame. It needs to go to one of 9 frames that are not in any mathematical order, meaning that there is no mathematical expression that will only return one of those 9 frames. So basically on frame 35 I want it to go to either frame 36, 110, 211, 316, 421, 602, 679, 747, or 820. Then, after each set of frames plays, I want it to go to another of those 9, hopefully not the one that it went to previously, but I will settle for any of the 9. PLEASE I have been wracking my somewhat limited knowledge of actionscript trying to get it to work but it just keeps doing things that seem strange. If anyone can tell me what to do it would be much appreciated.

P.S. Please test solutions if you are not sure they work because things that seem to me like they should work inexplicably do not. Thanks!

Go To Random Frame
I want to get a movie clip to get the root movie to go to a random frame, but I want the random frame to be a predetermined set - like frames 21 through 40. Does anyone know how? Right now I am using

_root.gotoAndStop(Math.ceil(Math.random()*45)+1);

But I need to just use the predetermined frames...

::::: Go To Random Frame:::::
i'd like to go to a random frame in a movie.
how would i do that?

tnx

Random Frame
Does any body here know how to create a button in flash that tells a movie target to go to and play a random frame

Random Frame?
Im really quite bad at actionscript, just learning -- is the following possible?

I have a movieclip "news", 10 frames. Each frame has a sentence on it.

I want scene 1 to get a random number and then do a:

news.gotoAndStop(randnumberhere)

so that it gets a random number, and goes to the proper frame inside the MC "news"

Possible? Can someone help me on the code?

TY,
~DW~

Random Frame
Is there a way to play a movie clips frames in a random order without repeating a frame?

How Do I Go To A Random Frame...
whats the action scripting to go to a random frame in a movie clip by clicking a button. can anyone help?

Random Frame
Hello.

Anyone know how to create a movieclip that will (on loading) go to a random frame?

Thanks

Random Frame
Hi,

I have a 7 frame root timeline.
1st frame is blank with only this frame action:
numFrames = _totalframes;
randomFrame = Math.floor (Math.random() * numFrames + 1);
gotoAndStop (randomFrame);

The next 6 frames ie 2 to 7, each contain a MC.
Each of these MCs upon having played their length, return the root timeline to frame 1, to send the root timeline to another random frame.

Works just fine. But how do I ensure that the same frame is NOT displayed more than twice?

Thanks

Random Frame
I used to have a cool lil script that you put on the first frame and it randomly goes to another frame on that timeline.

Can anyone help?

Random Frame?
has anyone got he code to tell the _root to go to a random frame of say frame 1 to 100 - much appreciated, thanks.

Random MC Frame? How?
Okay I have a MC with 6 frames and I want it to go and keep going to a random frame within the 6.

Thanks

Frame Random?
Ok.. Lets say this... When it reaches to "Frame 10" i want to make it randomly go to a specific such as "Frame 15" or "Frame 20"

Random Frame
hey, trying to make an AS that pick a random $ 1-10 and then goes to that frame. i think i just have a destial wrong in the code. could someone help me please?

basic idea is it says variable is random number 1-10, go Frame "variable"

thanks

Random Frame Help
I know how to make a button tell a movie clip land on a random frame,
e.g.

frame = Number(random(4))+1;
tellTarget ("yourcard") {
gotoAndStop(/:frame);
}

What I want is to have the movie clip "yourcard" have 13 labels and 4 frames for each label (it's a card game with the 4 suits after each label)

I'm sending a variable to tell the game what the card is (x=10 for example) I want the "yourcard" mc to land on a random frame ater each label (label=ten) but don't know how to script that.

Go To Random Frame
How would I target a movie clip to goto and stop on a random frame between 20 and 24?

I tried this but it doesn't work


} if (x==2) {
frame = Number(random(23))+20;
tellTarget ("last") {
gotoAndStop(/:frame);
}
}

Random Frame?
Hello..

I want a page to goto a random frame(2-5) when the page loads...
Only one problem: HOW??? ;o)

Random Frame
Hey guys,
I currently have a movie clip with the following script applied:

on (release) {
gotoAndStop ((_currentframe % _totalframes)+1);
}

so that on(release) it goes to the next frame in the movie.
How could I modify this so that instead of simply going to the next frame it goes to a random frame??

thanks heaps

Help - Random Frame?
When a user clicks a button, I want a movieclip (with 7 frames in it) to go to and stop at a random frame. How can I achieve this?

Random MC Frame Help
hello all.. can any 1 help me, i have started a project that needs to have a random frame in a movie clip...

what i have done ... if the position of the mouse is clicked in a particular area then goto myclip_mc, framelabel no_three and in this frame i have another movie clip (myrandomclip) wiv 4 different mc's in that 1 clip with stop features above each, which then
needs to be randomized when actioned.

i have tried gotoAndPlay (1+Math.floor(Math.random()*6)+1);

and (Math.floor(Math.random()*6)+1); and the old random feature but all seem not to work correctly..

(myrandomclip)
eg. square, triangle, circle (s,t,c)

square moves to the left
triangle moves up
circle moves to the right

it will randomize between each movieclip but not all the time it seems to freeze as if nothing is happening, no movement... is this down to my random action script or is it to do with the script on the movies within myrandomclip

any help will be much apreciated cheers all

Random Frame?
I want my movie to go to a random frame between 2-17. Frame 1 will tell it where to go. How do I do this? I only want it to happen once. (It will go to a randomly picked image every time a user views it on my website.) I hope this makes sense.

Random Frame Please
hi. can someone help me get a random frame in a movie clip? in other words, the movie clip starts at a random frame. but here's the twist... i have two instances of the same movie clip on the stage but when they go to random frames like i requested, they don't stop at the same frame. i need them to both land on the same frame every single time. ok. you with me? two instances of the same movie clip which need to be "synchronized". oh, one more thing... one of the movie clips is nested in another movie clip on the same. actually, it's double nested. how? how? how? please help, luma.

Copyright © 2005-08 www.BigResource.com, All rights reserved