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
Check this thread at Bit-101.
i found this in my old code library… it looks really funny.
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);
Wow, I sure hope my heart doesn’t beat that slow…hehehe. Nice script though man
that’s why you have the frequency parameter.
you could have a nice tachycardia if you want to.
Yeah I was playing with that for a bit
be careful, you might end up in the hospital…
Thanks to everyone who replied, especially lostinbeta for giving me a link to a great flash site! :beam:
No problem