PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
CS3 Scale movieClip but adjust X position of MC's to left and right of it
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Scale movieClip but adjust X position of MC's to left and right of it

  1. #1
    Senior Member
    Join Date
    Apr 2001
    Posts
    260

    Scale movieClip but adjust X position of MC's to left and right of it

    Hello,

    I have 4 movieClips on stage named text1, text2 etc. When I RollOver any one of them I have a tween which changes their xscale and yscale. So basically when you rollover they get bigger and when you rollout they go back to 100 scale.

    What I want to be able to do is make it so that if I hover over item 3 then item 4's x position is shifted according to the scale of item 3. I ALSO want to be able to move items 1 and 2 to the left to account for the new scale. I can do this but only by moving things to the right, I cannot understand how to make items to the left of that selected update their x position to account for the scale.

    the code I'm using is:
    Actionscript Code:
    function scalethis(mc, prop, end, time, type)
    {
        var sT:Tween = new Tween(mc, prop, type, mc[prop], end, time, true);
    }

    for (i=1; i<5; i++)
    {
        var t = _root["text"+i];
       
        t.onRollOver = function()
        {
            scalethis(this, "_xscale", 200, 1, Strong.easeOut);
            scalethis(this, "_yscale", 200, 1, Strong.easeOut);
        }
        t.onRollOut = function()
        {
            scalethis(this, "_xscale", 100, 1, Strong.easeOut);
            scalethis(this, "_yscale", 100, 1, Strong.easeOut);
        }
       
        this.onEnterFrame = function()
        {      
            for (i=1; i<5; i++)
            {
                nN = eval(_root["text"+i]);
                prevN = eval(_root["text"+(i-1)]);
                if (prevN == undefined) nN._x = 199;
                else nN._x = (prevN._x + (prevN._width/2)) + ((nN._width/2));      
            }
        }
       
    }

    The onEnterFrame function is working but only shifting the x position of items that are on the right of that currently selected - it doesn't scale the selected item and shift things left and right accordingly.

    Does that make sense and if so does anyone know how to implement?

    Cheers
    Matt
    Just starting out on the long road that is AS3 - and already want to turn back!!!
    FrApple - get a free iPad

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Make sure that the registration for each movie clip is in the top center.
    Code:
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    
    var spacing = 2;
    var boxes = [text1, text2, text3, text4];
    
    function scalethis(mc, prop, end, time, type) {
    	var st = new Tween(mc, prop, type, mc[prop], end, time, true);
    }
    for (i in boxes) {
    	boxes[i].onRollOver = function() {
    		scalethis(this,"_xscale",200,1,Strong.easeOut);
    		scalethis(this,"_yscale",200,1,Strong.easeOut);
    	};
    	boxes[i].onRollOut = function() {
    		scalethis(this,"_xscale",100,1,Strong.easeOut);
    		scalethis(this,"_yscale",100,1,Strong.easeOut);
    	};
    }
    this.onEnterFrame = function() {
    	for (i in boxes) {
    		if (i == 0) {
    			boxes[i]._x = 100+boxes[i]._width/2;
    		} else {
    			boxes[i]._x = (boxes[i-1]._x+(boxes[i-1]._width/2))+((boxes[i]._width/2))+spacing;
    		}
    	}
    };

  3. #3
    Senior Member
    Join Date
    Apr 2001
    Posts
    260
    You little beauty - many thanks.
    Just starting out on the long road that is AS3 - and already want to turn back!!!
    FrApple - get a free iPad

  4. #4
    Junior Member
    Join Date
    Nov 2007
    Posts
    14
    Nice code dawsonk.

    I tried changing the onEnterFrame to utilize onMotionChanged thinking it would be more efficient, it runs but gets a little buggy. Any ideas on doing it that way? Thanks for any input.

  5. #5
    :
    Join Date
    Dec 2002
    Posts
    3,518
    'onMotionChanged' is not more efficient in this case, because there can be multiple tweens happening at the same time, which would also cause it to run poorly.

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