A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Elastic scale issues

  1. #1
    Member
    Join Date
    Jan 2001
    Posts
    54

    Elastic scale issues

    I have some elastic scale code that I'm using, and it works for the most part. The actions in the first frame are the common:

    Code:
    Movieclip.prototype.elasticScale = function(target, accel, convert) {
    	xScale = xScale * accel + (target - this._xscale) * convert 
    	yScale = yScale * accel + (target - this._yscale) * convert 
    	this._xscale += xScale
    	this._yscale += yScale
    }
    
    stop();
    And there's a movieclip with this code on it:

    Code:
    onClipEvent (enterFrame) {
    	if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
    		elasticScale(120, 0.7, 0.3);
    	} else {
    		elasticScale(100, 0.7, 0.3);
    	}
    }
    And it scales/bounces perfectly. Problem is, once I add another movieclip with the same clipEvent actions, this second movieclip enlarges as is should *but also* makes the first movieclip jiggle. Any way to prevent this from happening?

  2. #2
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    You need to make xScale and yScale local to each movieClip....
    code:

    MovieClip.prototype.elasticScale = function(target, accel, convert) {
    this.xScale = this.xScale * accel + (target - this._xscale) * convert;
    this.yScale = this.yScale * accel + (target - this._yscale) * convert;
    this._xscale += this.xScale;
    this._yscale += this.yScale;
    }
    stop();

    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

  3. #3
    Member
    Join Date
    Jan 2001
    Posts
    54
    And I shall name my first born "Lexicon"! Thanks for the help - it makes perfect sense and worked like a charm.

    On a related note, do you (or anyone else) know of a way to set this up so that it's not dependent on having an "onClipEvent(enterFrame)" running continuously? I may have 10+ of these elastic movieclips on stage at once, and I'd rather not take the performance hit that I'm guessing they'll create.

  4. #4
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    There shouldn't be much of a performance hit.

    Have a look at "Springy Circles" 1 and 2, they have 200 of the same elastic function working at once....

    http://www.lexicon-design.co.uk/port...flash&dnum=ALL

    If it runs ok, then don't worry about it.
    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

  5. #5
    Junior Member
    Join Date
    Feb 2002
    Posts
    26
    Hi guys,
    I'm trying to adapt a bit of this code, but I'm running into a problem i can't figure out.

    I've got a 'blank' movieclip with this code embedded, and I drop this movieclip into others that I want this effect to be applied to.

    function elasticScale(target, accel, convert) {
    _parent.graphic.xScale = (_parent.graphic.xScale * accel + (target - _parent.graphic._xscale) * convert);
    _parent.graphic.yScale = _parent.graphic.yScale * accel + (target - _parent.graphic._yscale) * convert;
    _parent.graphic._xscale += _parent.graphic.xScale;
    _parent.graphic._yscale += _parent.graphic.yScale;
    stop();
    }

    _parent.onRollOver = function(){
    yayuh =1;
    }

    _parent.onRollOut = function(){
    yayuh = 0;
    }


    _root.onEnterFrame = function() {
    if (yayuh ==1){
    if (_parent.graphic.hitTest(_root._xmouse, _root._ymouse, true)) {
    elasticScale(150, 0.7, 0.3);
    } else {
    elasticScale(100, 0.7, 0.3);
    }
    }
    }


    When tracing for _parent.graphic.xScale, im getting NaN. Do I need to initialize these variables? Do you know what I'm doing wrong? Thanks.
    Last edited by therejoer; 12-09-2008 at 10:20 PM.

  6. #6
    Junior Member
    Join Date
    Feb 2002
    Posts
    26
    never mind, figured it out. All it took was to initialize _parent.graphic.xScale with 1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center