A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: stop moving when mouse is outside certain area (parallax scroller)

  1. #1
    Senior Member onine's Avatar
    Join Date
    Mar 2005
    Posts
    627

    stop moving when mouse is outside certain area (parallax scroller)

    Hi everyone.
    I have a problem with a "paralax scroller" movie clip. I downloaded the original from this site and I'm currently modifying it. Currently I'm loading it into the .swf as another .swf like this:
    Code:
    loadMovie("parallax_01.swf", parallax_mc);
    which is fine.

    My problem is that it continues to scroll even when the mouse isn't over it. Please check it out here to see what I mean. As you can see, it works perfectly, as long as the mouse remains within the bounds of the loaded .swf, but once outside those bounds - ie outside the box - it continues to scroll (which is bad).

    Can anyone help me modify my code so that this can be fixed? I guess its something about checking where the mouse is? getBounds maybe? The code governing the movement is inside the loaded "parallax_01.swf" and reads as follows:
    (foreground layer)
    Code:
    onClipEvent (enterFrame) {
    	if (_root.parallax_mc.mainVar == 0) {
    		homeX = (-_root.parallax_mc._xmouse*3)+540;
    	} else {
    		homeX = (-_root.parallax_mc.mainVar*3)+540;
    	}
    	thisX = _x;
    	diffX = homeX-thisX;
    	if (_root.parallax_mc.mainVar == 0) {
    		moveX = diffX/30;
    	} else {
    		moveX = diffX/5;
    	}
    	_x = thisX+moveX;
    }
    (middleground layer)
    Code:
    onClipEvent (enterFrame) {
    	if (_root.parallax_mc.mainVar == 0) {
    		homeX = (-_root.parallax_mc._xmouse*2)+405;
    	} else {
    		homeX = (-_root.parallax_mc.mainVar*2)+405;
    	}
    	thisX = _x;
    	diffX = homeX-thisX;
    	if (_root.parallax_mc.mainVar == 0) {
    		moveX = diffX/30;
    	} else {
    		moveX = diffX/5;
    	}
    	_x = thisX+moveX;
    }
    (background layer)
    Code:
    onClipEvent (enterFrame) {
    	if (_root.parallax_mc.mainVar == 0) {
    		homeX = (-_root.parallax_mc._xmouse)+270;
    	} else {
    		homeX = (-_root.parallax_mc.mainVar)+270;
    	}
    	thisX = _x;
    	diffX = homeX-thisX;
    	if (_root.parallax_mc.mainVar == 0) {
    		moveX = diffX/30;
    	} else {
    		moveX = diffX/5;
    	}
    	_x = thisX+moveX;
    }
    I'm sure its fairly simple but I just can't figure it out. Thank you for looking I really appreciate it.

  2. #2
    Senior Member
    Join Date
    Jul 2005
    Posts
    692
    Can't you just use an onRollout? just make it stop?

  3. #3
    Senior Member onine's Avatar
    Join Date
    Mar 2005
    Posts
    627
    I dunno - can I?
    I'm still a newb really and this is someone else's code. So where do I put the onRollout code and what should it say? Thanks!

  4. #4
    Senior Member onine's Avatar
    Join Date
    Mar 2005
    Posts
    627
    Hey, thanks blazes. Got it working like this:
    created an invisible button underneath with this code:
    Code:
    on (rollOver) {
    	posRight = "yes";
    }
    on (rollOut) {
    	posRight = "no";
    }
    then altered the layer code like this:
    Code:
    onClipEvent (enterFrame) {
    	if (_parent._parent.posRight == "yes"){
    		if (_root.parallax_mc.mainVar == 0) {
    			homeX = (-_root.parallax_mc._xmouse*3)+540;
    		} else {
    			homeX = (-_root.parallax_mc.mainVar*3)+540;
    		}
    		thisX = _x;
    		diffX = homeX-thisX;
    		if (_root.parallax_mc.mainVar == 0) {
    			moveX = diffX/30;
    		} else {
    			moveX = diffX/5;
    		}
    		_x = thisX+moveX;
    	}
    }
    probably pretty messy code but hell, it works. Thanks for the suggestion - it worked a treat

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