To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Reply
 
Thread Tools Search this Thread Display Modes
Old 10-14-2004, 08:43 PM   #1
addamtron
Senior Member
 
Join Date: May 2003
Posts: 160
Bubbles Floating Upward?

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!
addamtron is offline   Reply With Quote
Old 10-14-2004, 08:55 PM   #2
MindWire
Member
 
Join Date: Oct 2003
Location: Colorado Springs
Posts: 82
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.
__________________
Justin Blough
MindWireMedia
(719) 659-8062
justin.blough@mindwiremedia.net
http://www.mindwiremedia.net
MindWire is offline   Reply With Quote
Old 10-14-2004, 09:05 PM   #3
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
See attached fla.

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);
}


Attached Files
File Type: fla hearts.fla (16.5 KB, 4633 views)
__________________
jbum is offline   Reply With Quote
Old 10-14-2004, 09:26 PM   #4
addamtron
Senior Member
 
Join Date: May 2003
Posts: 160
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.
addamtron is offline   Reply With Quote
Old 10-14-2004, 10:51 PM   #5
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
Change this line:

this._x += sway;

to this:

this._x += sway*kDistance;

where kDistance is a larger number like 5 or 10.
__________________
jbum is offline   Reply With Quote
Old 10-14-2004, 10:58 PM   #6
addamtron
Senior Member
 
Join Date: May 2003
Posts: 160
i tried messing with it and can't seem to get it running at a smooth pace, it's either too fast or too slow.
addamtron is offline   Reply With Quote
Old 10-14-2004, 11:08 PM   #7
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
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.

It's best to tweak one number at a time.
__________________
jbum is offline   Reply With Quote
Old 04-20-2006, 10:26 AM   #8
streeterw
Junior Member
 
Join Date: Apr 2006
Posts: 1
Graphic Design Student/Professional

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!
streeterw is offline   Reply With Quote
Old 08-23-2006, 01:39 AM   #9
bjones
Junior Member
 
Join Date: Sep 2000
Posts: 1
why do the hearts after a few minutes all end up on left side?
bjones is offline   Reply With Quote
Old 09-25-2006, 01:33 PM   #10
sd12013
Junior Member
 
Join Date: Sep 2006
Posts: 4
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.

-R
sd12013 is offline   Reply With Quote
Old 09-26-2006, 04:55 AM   #11
Halidon
Junior Member
 
Join Date: Sep 2006
Posts: 1
Modified version

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.

Thanks,
Halidon
Halidon is offline   Reply With Quote
Old 09-30-2006, 10:22 AM   #12
percepts
an old dog learning new tricks
 
Join Date: Feb 2003
Location: Devon UK
Posts: 83
just came across I nice implementation of bubbles

http://www.freakfish.co.uk/


if you want a giggle and have the tools, take a look at where the bubbles are coming from!
percepts is offline   Reply With Quote
Old 10-24-2006, 05:29 PM   #13
sd12013
Junior Member
 
Join Date: Sep 2006
Posts: 4
Here's another instance:
http://www.aquasphereswim.com/home.html
sd12013 is offline   Reply With Quote
Old 11-27-2006, 03:34 PM   #14
sd12013
Junior Member
 
Join Date: Sep 2006
Posts: 4
...and another one

http://www.candystand.com/bubble-gum/index.do
sd12013 is offline   Reply With Quote
Old 03-06-2008, 07:47 PM   #15
flashgurl90
Member
 
Join Date: May 2007
Posts: 80
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
flashgurl90 is offline   Reply With Quote
Old 03-21-2008, 04:22 PM   #16
marvincat
Junior Member
 
Join Date: Mar 2008
Posts: 1
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!!!
marvincat is offline   Reply With Quote
Old 11-10-2008, 07:21 AM   #17
beuvvema
Junior Member
 
Join Date: Nov 2008
Posts: 1
Quote:
Originally Posted by bjones
why do the hearts after a few minutes all end up on left side?
Hi All,

being a newbie to Flash / Actionscript I am struggeling with the same issue, after some time the hearts end up at the left.

Has anyone got a clue or a solution to make this super .fla even better?

Kind regards
Beuvema
beuvvema is offline   Reply With Quote
Old 10-08-2009, 06:52 AM   #18
lose-it
Junior Member
 
Join Date: Oct 2009
Posts: 1
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 it??

I await your response!!
lose-it is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:37 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.