PDA

View Full Version : elastic scale function


lelales
12-05-2005, 06:53 PM
I'm trying to do a simple elastic scaling function, but it doesn't work.

I have the following code:elasticscale=function(tar, accel, convert) {

xScale = xScale*accel+(tar-this._xscale)*convert;
yScale = yScale*accel+(tar-this._yscale)*convert;
this._xscale += xScale;
this._yscale += yScale;
};

then:mc.onEnterFrame=this.elasticsScale(100, 0,5, .4);

it works fine when placed on a clip, as follows:onClipEvent (load) {
this.elasticScale = function(tar, accel, convert) {
xScale = xScale*accel+(tar-this._xscale)*convert;
yScale = yScale*accel+(tar-this._yscale)*convert;
this._xscale += xScale;
this._yscale += yScale;
};
}
onClipEvent (enterFrame) {

this.elasticScale(100, 0.5, 0.4);

} but when I remove the code from the clip, change the syntax, and place it on a keyframe, it doesn't work.

here's my file: http://www.caillouette.com/sb_elastic.zip

thanks

Artech
12-05-2005, 08:04 PM
you have

mc.onEnterFrame=this.elasticsScale(100, 0,5, .4);

using the word this means it would only find a local implementation of "elasticsScale"

If you want it to be able to access the function elsewhere you need to tell it. Depending on the relative location _root.elasticsScale(), _parent.elasticsScale(), or mc.elasticScale() could work.

Duffman
12-05-2005, 08:19 PM
check out the tween class
http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00004142.html

lelales
12-05-2005, 08:22 PM
sorry but your suggestion didn't work.

I thought there would be a simple answer to this, since the code that is attached to the mc works, but off the mc, I can't quite get it.

thanks again
And thanks Duffman but I'm not using a tween. It's a sort of bounce effect.

any other ideas?

thanks

lelales
12-05-2005, 10:06 PM
Pretty please? I've been working on this for 2 days and it should be simple.

I just can't figure it out.

many thanks

Suicidal.Banana
12-06-2005, 06:57 AM
tryed something like this?
mc.onEnterFrame=function() {
elasticsScale(100, 0,5, .4);
}

lelales
12-06-2005, 01:12 PM
tryed something like this?
mc.onEnterFrame=function() {
elasticsScale(100, 0,5, .4);
}


Yep I tried it. and it still doesn't work.

thanks

Suicidal.Banana
12-06-2005, 02:05 PM
Yep I tried it. and it still doesn't work.

thanks
and

elasticsScale('100', '0,5', '.4');

or with " instead of '
and should it be 0.5 or 0,5

lelales
12-06-2005, 11:12 PM
Here's my code, but it doesn't work.
elasticscale=function(tar, accel, convert) {

xScale = xScale*accel+(tar-this._xscale)*convert;
yScale = yScale*accel+(tar-this._yscale)*convert;
box._xscale += xScale;
box._yscale += yScale;
};
var theTarget = box;
box.onEnterFrame = function() {elasticscale(200, 0.5, 0.4);};

I tried your suggestions with no luck.

Here's alink to someone working on the same problem, but they're turning the code into a prototype:http://www.actionscript.org/forums/showthread.php3?t=88451

Maybe someone has some other code I could use?

thakns again

deadbeat
12-06-2005, 11:29 PM
Are you aware that the Tween class has both a Bounce and Elastic tween type?

K.

fmx
12-06-2005, 11:47 PM
is this what you're talking about?
(see attachment)

lelales
12-07-2005, 12:23 AM
That should do the trick.

thanks again.