AS3 - Gaussian / Weighted Random Distribution
Hi all.
I'm trying to create a weighted random distribution, and can't figure out how to go about it. basically I want to create a starry sky, where most of the stars are in the middle of the screen. by making the y random, like:
Code:
star.y =Math.random()*_mc.stage.stageHeight;
I just get an even distribution on the Y axis. What I really want is to have most of the stars near _mc.stage.stageHeight/2.
Anyone has a good idea of how to accomplish?
thanks!
Ultrashock Forums > Flash > ActionScript
Posted on: 4 Weeks Ago
View Complete Forum Thread with Replies
Sponsored Links:
Generating Random Numbers From Normal(Gaussian) Distribution
We are in the process of builing a statistics simulation for a client. One of the requirements of the simulation is to first generate a set of 1000 random numbers from a Normal (or Guassian) distribution.
Does ActionScript have the builty in functionality to generate random numbers from anything other than a Uniform distribution?
If this functionality is not built in, does anyone know of a component or pre-built script that can provide this functionality?
How hard would it be, if either of the two options above are not possible, to generate random numbers from a Normal(Guassian) distribuion using ActionScript?
Thanks in advance for any help!!!
Aaron
View Replies !
View Related
[CS3] Weighted Random Text Generator
I've seen a few threads on this but they seem to be buried pretty deep in the archives. I'd like to build a random text selection script, one that is weighted so that certain text shows up more often. Using AS2 to do so, what would be the best way? This'll be used as a Sponsorship bar mostly on a website. Text would be weighted like this: Sponsor texts - 1, showing up most of the time. Website announcements, sales, etc, weighted 2, showing up more often. Based on previous threads, this:
Code:
RanNum = Math.ceil(Math.random()*Number(this.quoteCount));
ran = this["quote"+RanNum];
quote_txt.text = ran;
seems like it'd be the best way - but how would you make it weighted?
View Replies !
View Related
Curved Random Distribution
How do I get a curved/scewed random distribution?
ie, if I wanted a random number between 0 and 100, but the lower a number is the more likely it is to show up. So 100 would show up very few times, and 1 would show up more often.
Anyone know the best way to do this? I have only come up with cumbersome ways of doing this.
View Replies !
View Related
Natural Timings: Random Probability Distribution
i'm doing a game where a mole pops out of a hole at random intervals.
the intervals need to be between two limits, and be biased to a time between those limits,
eg. the mole should pop out after a wait of 1 to 5 seconds (chosen randomly) but should statistically pop out more often in the 2sec region. It might be written like this:
delay=biasedRandom(1,2,5)
i'm calling this problem "setting the probability distribution of a random number"
A function like this would be really handy for making things more naturalistic.
I've tried a few methods but i've got deadlines and my head was exploding.
Any ideas?
View Replies !
View Related
Calculating Weighted Average
I'm using the below AS but it just doesn't seem to be working...
Looks like the actionscript referencing is OK it just seems to be getting stuck on the / in the result_product calculation.
Let me know if this needs further explanation. I'd have no problem posting the source fla
function onCalculate() {
one = Number(number_one);
two = Number(number_two);
three = Number(number_three);
four = Number(number_four);
ten = Number(number_ten);
eleven = Number(number_eleven);
twelve = Number(number_twelve);
thirteen = Number(number_thirteen);
result_sum = one + two + three + four;
result_product = ((one * ten) + (two * twelve) + (three * thirteen) + (four * fourteen)) / (one + two + three + four);
}
View Replies !
View Related
Light-weighted Animations Of Images ?
Dear all,
I found this fla somewhere on the net which I do not remember.
The only thing I know is it was not made up of several images but only few (maybe 2 or 3 images) by looking at the file's size
There must be a special tweening technique that the author has used to make this fla but I do not know what it is.
Do you know or have you ever come across this technique?
View Replies !
View Related
Gaussian Elimination
I have written this code for perfoming a guassian elimination with pivot
Code:
i = 0;
j = 0;
//
A = [[-2, 1, 2, -3], [2, 1, -1, 8], [-3, -1, 2, -11]];
//
m = A.length;
n = A[0].length;
//
trace(A[0]);
trace(A[1]);
trace(A[2]);
trace("---------start");
do {
// Find pivot in column j, starting in row i:
max_val = A[i][j];
max_ind = i;
// for k=i+1 to m do
for (k=i+1; k<m; k++) {
val = A[k][j];
if (Math.abs(val)>Math.abs(max_val)) {
max_val = val;
max_ind = k;
}
}
//
if (max_val !== 0) {
// switch rows i and max_ind
temp = A[i].slice();
A[i] = A[max_ind].slice();
A[max_ind] = temp.slice();
// divide row i by max_val
for (var loop = n-1; loop>=0; loop--) {
A[i][loop] /= max_val;
}
for (u=m-1; u>=0; u--) {
if (u<>i) {
// add - A[u][j] * row i to row u
for (var loop = n-1; loop>=0; loop--) {
A[u][loop] += -A[u][j]*A[i][loop];
}
}
}
i++;
}
j++;
} while (i<m and j<n);
trace(A[0]);
//
trace(A[1]);
trace(A[2]);
trace("---------end");
I have been follwing the pseudo code from wiki
http://en.wikipedia.org/wiki/Gaussian_elimination
so you can see where I'm coming from and where it should end up
this didn't work but then I read another paper and it lead me to think that the loops should be done in reverse. I have implemented this, but would love someone to check it over.
View Replies !
View Related
Gaussian Blurs?
Hi all;
I was wondering; is there any way to make a Gaussian Blur effect in Flash, to make something look out of focus? I know you can just use Photoshop or some such program to blur a bitmap and then import it into Flash, but I was wondering if Flash can do it directly, with a vector object.
TIA!
View Replies !
View Related
Blur Effect (gaussian)
Is there a speacial effect to create this blur effect on an bitmap in Flash
http://www.vw.com/phaeton/mini/flash.htm
Look under the "FEATURES" button.
At First the bitmap is clear, then they create a blur effect
on top of it . Does anyone know how they do that.
Thanks in advance
Roy Oonk
Netherlands
View Replies !
View Related
Gaussian Blur Effect
hi... i want to create a effect that u put on transitions between movieclips in a website... a gaussian blur effect... do some one knwo how to create this?? will be very greatful with an answer
View Replies !
View Related
Gaussian Blur Effect?
Does anyone know how to make a guassian blur effect similar to the vertical stripe on this site?
http://www.pedro-verhue.be/
The blur filter on 'high' is supposed to do the trick, but i'm not getting results anywhere near as clean as that site. Thanks in advanced.
View Replies !
View Related
Gaussian Blur Effect
hi... i want to create a effect that u put on transitions between movieclips in a website... a gaussian blur effect... do some one knwo how to create this?? will be very greatful with an answer
View Replies !
View Related
Distribution By E-mail
Wich is the best, most elegant, professional an direct way to distribute a standalone work by e-mail?
Is there a anyother way than insert it as a adjunt file?(sorry for my english)
Thank you!!!!
Great web site this one...
View Replies !
View Related
Spatial Distribution
Hi all,
I'm looking for an algorithm which distributes a set number of squares
across a fixed size plane in a nice random manner.
In a memory/match game I want the cards not arranged in a grid
(preferably not even a grid with some freedom of movement in it's
squares) but in a true random fashion.
I tried to find algorithms on the web, but the ones I found did not
match my problem (or I missed it)
Does anyone knowmaybe a name of such an algorithm or have any (pseudo)code?
Thanks in advance,
Manno
--
----------
Manno Bult
http://www.aloft.nl
View Replies !
View Related
Array Nav Distribution
I've been working on a Navigator that uses an Array to get it's information. I've used countless scripts from countless threads and have managed to produced a simple Vertical menu.
Problem is, I need it to be Horizontal. The bigger problem is, I wanted the buttons to distribute evenly. I can't figure out how to tell Flash to calculate the various widths of the buttons and align them horizontally... with a little bit of spacing too. Any help would be greatly appriciated.
Code:
// Button Array
var buttonArray:Array = new Array("home", "about", "services", "prices", "contact");
/////// Button Menu ////////
function RollOver(btnInfo) {
var button = this[btnInfo];
newColour = new Color(button.bg);
newColour.setRGB(0xE4C5C5);
}
function RollOut(btnInfo) {
var button = this[btnInfo];
newColour = new Color(button.bg);
newColour.setRGB(0xFFFFFF);
}
for (var i = 0; i<buttonArray.length; i++) {
attachMovie("button","menuBar",this.getNextHighestDepth()); //Places button onto stage
var menuSizeVar = menuBar._height*buttonArray.length+(2*buttonArray.length); // Calculates spacing and positioning
var Align = i*(menuBar._height+2)-menuSizeVar; // Aligns the buttons vertically
duplicate = menuBar.duplicateMovieClip("btn"+i, i, {_y:Align}); // Creates buttons according to the array
this["btn"+i].btnText.text = buttonArray[i]; //Places text into the buttons accroding to the array
this["btn"+i].btnText.autoSize = true;// Allow textbox to reseize
this["btn"+i].bg._width = this["btn"+i].btnText._width+10;// Make button background the same width as the text
this["btn"+i].btnAndNum = ["btn"+i]; //Creates a Paramater for later on
//Rollover Button
this["btn"+i].onRollOver = function() {
RollOver(this.btnAndNum); // uses the paramaters to create a function
};
//Rolloff Button
this["btn"+i].onRollOut = this["btn"+i].onReleaseOutside=function () {
RollOut(this.btnAndNum); // uses the paramaters to create a function
};
}
View Replies !
View Related
Math: Distribution On A Circle
I'm faced with a problem:
I'm trying to duplicate & evenly distribute a movieclip around the circumfrence of a circle. Additionally I need to appropriately rotate each clip (for example: if I was using an image of an arrow, each would be pointing to the centre of the circle).
Can anyone help me figure out the math, or should I just go back to high school?
Thankyou,
Justin
View Replies !
View Related
Picture Browser On Cd For Distribution
I need to write a photo album application that I can put on a CD that will allow the user to browse the pictures on the cd (which will be in different directories on each cd) and possibly other things.
I am very new to flash so I'm not really sure if this is at all possible. I have seen some actionscript tutorial/demos that do exactly what I want, but I don't think I can put those on a cd.
Basically any help I can receive is greatly appreciated, like if this is even possible, helpful tutorials, or maybe ideas about a different approach I could take that would be easier.
Thank you flash people.
View Replies !
View Related
Uneaven Weight Distribution
I have been having problems with a preloader. It takes forever to show any sort of display. The pre loader is the one with the percentage progress bar found elsewhere on the Kirupa site, and I have it in its own scene, with the rest of the movie in "Main".
Cutting a long story short, the following is a snippet of the size report of the export to movie...
FrameFrame # Frame Bytes Total Bytes Page
------------ ----------- ----------- ---------------
1 140803 140803 Scene 1
2 350 141153 2
3 47 141200 3
4 27 141227 4
5 5375 146602 Main
6 13 146615 2
7 13 146628 3
8 13 146641 4
9 13 146654 5
10 16 146670 6
11 69 146739 7
The real "weight" of the movie should be in the "Main" scene, but it is showing in Scene 1, Frame 1.
Does anyone know how to redistribute the weight so that the pre-loader can work properly please?
Thanks in anticipation.
Martin
View Replies !
View Related
Flash MX2004 Player Distribution?
A Flash application has to be installed on computer that doesn't have an internet connection. It must be available through Internet Explorer.
Where can I find a player distribution for IE? I found it for Netscape, Firefox and other browsers, but not for IE.
Thanks!
View Replies !
View Related
Large Scale Distribution-CD/Flash 5/html
Hi all,
I am usually a lurker on this list, but have come out of hiding in need of advise. I have a CD ROM project that is going to be distributed to the tune of 10,000 mailings. It is an html/Flash 5 interface that opens PTViewer panorama files in large format in a separate window. Currently it has an autorun.
I have never done a project of this magnitude and have always had limited distribution where I knew the system(s) that it was going to be played on.
My question is - what advise would you give in terms of safeguards and error checking to ensure proper playback and execution?
Thanks in advance,
mscp22
http://www.aeidigital.com
View Replies !
View Related
[CS3] HELP Point Distribution System Horribly Broken
I'm working on building a point distribution system, but thus far absolutely nothing is working with it. It should be simple - an if/else testing if the max limit of points has been distributed into one specific area, and how many points are left in the pool. I got the subtraction/addition working - halfway - but the system is broken. Whenever someone adds points, it stops at 10 like it should.. or 9. But, when someone subtracts points, it jumps up to 11 and then goes down. The same thing happens when someone adds, and the counter is set at 0. It goes -down- to -1 first, then back up. This really breaks the entire system and renders it useless until a fix can be found, but thus far not much luck. Has anyone ever encountered this problem before?
View Replies !
View Related
Attach Movie Particles (distribution Question)
Hi I am trying to create some new effects where I attach multiple copies of a movie clip to another object. In this example it is another movieclip.
The problem I am experiencing is how to randomly distribute the clips over the object. I know I should be attaching them directly to the movie clip but haven't got it to work so far.
I thought about adding a hitTest so that they will only be visible when they are directly over my main movie clip.
I welcome any criticism over the way this has been set up. I welcome any ideas on a more flexible way to set this up. Please put me out my misery.
View Replies !
View Related
Maintaining Alignment/Distribution Of Objects During Browser Scaling
Hello All,
I have been searching the forum for about two hours trying to find the right code.
Basically, I want to have a site where the background scales to the browser window proportionately and the buttons re-align themselves around the perimeter. The content will be centered in the middle of the browser.
I found the perfect piece of code for the background scaling.
What I want to have is a minimum flash size, say 500px. If the browser window is scaled smaller then 500px, scroll bars appear. There will be buttons along the top, bottom, and sides of the stage. When the browser window is enlarged, the stage expands with the buttons staying the same size and distribution between each button on the stage is consistent. (more space between the buttons when stage is expanded.) Also, the buttons will stay position to the top, bottom, and sides of the browser.
I tried mixing other code from the forum with this scale code below with bad results.
Any help would be great.
Thanks
Jessy
Attach Code
Stage.scaleMode = "noScale";
//Auto Resize
stageListener = new Object();
stageListener.onResize = function() {
backgroundResize(_root.image_mc);
};
Stage.addListener(stageListener);
//Background Resize
function backgroundResize(image) {
var imageHeight = 560;
var imageWidth = 980;
var wRatio = Stage.width/imageWidth;
var hRatio = Stage.height/imageHeight;
//Larger Ratio
if (wRatio>hRatio) {
var ratio = wRatio;
} else {
var ratio = hRatio;
}
//Resize
if (Stage.width<=imageWidth && Stage.height<=imageHeight) {
image._width = imageWidth;
image._height = imageHeight;
} else {
image._width = imageWidth*ratio;
image._height = imageHeight*ratio;
}
}
backgroundResize(_root.image_mc);
View Replies !
View Related
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?
View Replies !
View Related
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??????
View Replies !
View Related
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;
}
View Replies !
View Related
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?
View Replies !
View Related
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]
View Replies !
View Related
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?
View Replies !
View Related
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??
View Replies !
View Related
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???
View Replies !
View Related
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
View Replies !
View Related
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
View Replies !
View Related
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
View Replies !
View Related
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.
View Replies !
View Related
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
}
}
View Replies !
View Related
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?
View Replies !
View Related
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?
View Replies !
View Related
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?
View Replies !
View Related
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?
View Replies !
View Related
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
View Replies !
View Related
|