PDA

View Full Version : Beating Heart



UrbaNomad
May 12th, 2003, 05:54 PM
I am trying to make a beating heart using actionscript. I'm trying to use the onClipEvent method used in kirupa's Movement Using ActionScript tutorial. I was able to make a continuously growing heart by simply using MovieClip._xscale and MovieClip._yscale, but to make it beat seems a bit more difficult.
I tried to put a variable in the onClipEvent that I could counter, so that I could mod it and do an if/else based on the outcome but uh... then I realized it reinitializes the variable every time lol.
Is there a way I could make the variable somewhere other than inside the onClipEvent? I think that is the simplest, but I am open to other suggestions on how to do this. It is sort of like the basis for a lot of the animation you could do in flash as I see it.
Thanks,
UrbaNomad

lostinbeta
May 12th, 2003, 06:38 PM
Check this thread at Bit-101.

http://www.bit-101.com/forum/viewtopic.php?t=552

kode
May 12th, 2003, 07:21 PM
i found this in my old code library... it looks really funny. :P

MovieClip.prototype.beat = function(strength, frequency) {
var p, s, t, a = .6, r = .8;
this.onEnterFrame = function() {
if (t++>=frequency) p = 100+strength, t = 0;
else p = 100;
this._xscale = this._yscale += s=s*a+(p-this._xscale)*r;
};
};
myMovieClip.beat(40, 24);

lostinbeta
May 12th, 2003, 08:03 PM
Wow, I sure hope my heart doesn't beat that slow....hehehe. Nice script though man :)

kode
May 12th, 2003, 08:08 PM
that's why you have the frequency parameter. ;)
you could have a nice tachycardia if you want to. :P

lostinbeta
May 12th, 2003, 08:10 PM
Yeah I was playing with that for a bit :)

kode
May 12th, 2003, 08:20 PM
;)

be careful, you might end up in the hospital... :P

UrbaNomad
May 13th, 2003, 10:12 AM
Thanks to everyone who replied, especially lostinbeta for giving me a link to a great flash site! :beam:

lostinbeta
May 13th, 2003, 01:35 PM
No problem :)