I would like to create a banner for my site that has little hearts floating upward. I would like them to have a random _y start position, random size, and sway on a sine wave curve. It would be great if I could define the max amount of hearts to be on stage at once or have a timer that defines how often a heart gets spawned. Can someone please help me out? THANKS!
look at duplicating movie clips.
for max ammount on stage set parameters for y, so if the mc goes off the top of the swf screen then it would remove itself from the swiff. When you create a new duplicate, increase the count number. But before you duplicate a clip make sure the number you have been incrementing is not greater than the max ammount. Make sure to decrease the incrementing variable when you remove a movie clip.
I havn't done much with sin or cos but if you create a movie clip that sets its y to random number in onClipEvent(load) then when you duplicate a movieclip, it will inherit those properties and move according to however you specify.
This is the script. It assumes there is an exported movieclip in the library called 'hearts' that contains 3 frames, each with a picture of a different style heart.
code:
kNbrHearts = 60; // number of hearts
kNbrPix = 3; // number of heart pix
kMinSpeed = 1; // minimum rise speed
kMaxSpeed = 20; // maximum rise speed
kMinSway = .0001; // minimum sway
kMaxSway = .01; // maximum sway
kSwayAmplitude = 15;
SW = Stage.width;
SH = Stage.height;
moveHeart = function()
{
var a = this.phase + getTimer()*this.sway;
var sway = Math.sin(a);
this._x += sway;
this._rotation = sway*kSwayAmplitude;
this._y -= this.speed;
if (this._y < -this._height) {
this._y = SH+this._height;
}
}
for (i = 1; i <= kNbrHearts; ++i)
{
var mc = _root.attachMovie('hearts', 'heart_' + i, i);
mc._x = random(SW);
mc._y = random(SH);
mc.onEnterFrame = moveHeart;
mc._alpha = 50 + random(50);
mc.phase = Math.random()*2*Math.PI;
mc.speed = kMinSpeed + Math.random()*(kMaxSpeed - kMinSpeed);
mc.sway = kMinSway + Math.random()*(kMaxSway - kMinSway);
mc.gotoAndStop(random(kNbrPix ) + 1);
}
thanks for the responses. that example is sort of what i'm looking for.. i would like the hearts to sway on a sine wave but not stay in one spot while doing so. i was thinking the sine way would be a way for the heart to move left and right on the screen as it floats upward. in your example the heart stays in the same spot and floats upward.
I would suggest increasing the frame rate (to 30) if you haven't done so, to add smoothness, and continuing to play with the kMinSpeed and kMaxSpeed numbers. Somewhere between too slow and too fast there must be a 'just right' hiding.
Also, you might want to turn off the 'sway' stuff till you get the vertical motion right (the adjustments to _y), then work on the sway separately.
I am creating a web page for the class I am taking in college. I applied your floating hearts action script to my web page, omitting the hearts graphic and adding a bubble graphic I created. I would My web page has two scenes. Scene one is a game that links to Scene 2 which houses the web pages. When I appy the action script to scene two which is were i would like the bubbles to be, the game opens up without the bubbles showing. However, once I link to the home page of the Scene two and go back to Scene one the bubbles are on scene one. This posses a problem because it effects the movement of the mouse and the game cannot be played properly. Therefore, I have two questions.
1. Is there anyway I can incorporate the action script so that it only is applied to Scene two and not Scene 1?
2. Is there any way to link one Flash document to another Flash document without creating separate Scenes? This would allow only the web page to have the action script and not the game
I am using Macromedia Flas MX 2004. This assignment is for my Senior Capstone project and need HELP!
Is there a way to have multiple instances of the effect?
Is there a way to have multiple instances of the effect? For instance, over the entire stage as a background effect but also coming out of a treasure chest that opens say every two seconds?
I tried to put the code into its own mc and drop a few instances on the scene but only one will play. Any help is greatly appreciated.
Im creating a side menu for a web site for college. I have decided to go with 6 menu items in the appearance of bubbles. I would like them to float upwards swaying side to side.
I have already created the 6 menu items. The modification, obviously, would be the fact that the hearts created were random and there were heaps of them.
I would like to link just the 6 menu items and have them float up starting in a random position, random speed and random sway movement.
I know this is alot to ask, i have tried modifying the code above, but im not that familiar with action script.
Hey, i love this bit of AS its exactly what im looking for. im trying to use this code with 1 my image of bubbles, but i only want it to play for 50 frames of the scene, and currently it plays through the whole movie. Do you know how can i stop it from playing at a certain point? and how do i constrain it to a certain area? Many thanks
This is great! I'm also trying to restrain it to a certain area. Any ideas?
Also, how ca I import it into another fla? I tried everything but it just doesn't work.
Thanks!!!
I have the exact same problem they all seem ot end up on the left!! Does anyone have a solution for htis or a bit of code that will stop Liability Insurance??