A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: a simple one... if mc._x<-200, how to stop the mc moving?

  1. #1
    user in A minor
    Join Date
    Jan 2005
    Location
    finland
    Posts
    121

    [F8] a simple one... if mc._x<-200, how to stop the mc moving?

    this is simple and reveals my non existent ac skills:
    i have a simple sideways scrolling menu. it functions ok, but i don't manage to stop the scroll when the menu_mc has reached it's end, that it, when menu_mc._x < -200. i've tried different if-statements without success. here's the part that does work all right:
    Code:
    _root.onEnterFrame = function() {
    if (_root._ymouse > 50 && _root._ymouse < 150 and _root._xmouse >-10 && _root._xmouse <900){
            menu_mc._x -= (_xmouse+menu_mc._x)/4;
    	pointer_mc._x += (_xmouse-pointer_mc._x)/6;
    	}
    }
    i know, i should manage to do this myself, but i don't seem to get it just right. as always, i'm grateful for help...
    Last edited by mrk13; 09-11-2006 at 09:49 AM. Reason: forgot flash version

  2. #2
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    add an additional requirement to the if statement...

    Code:
    _root.onEnterFrame = function() {
    if (_root._ymouse > 50 && _root._ymouse < 150 and _root._xmouse >-10 && _root._xmouse <900  && menu_mc._x > -200){
            menu_mc._x -= (_xmouse+menu_mc._x)/4;
    	pointer_mc._x += (_xmouse-pointer_mc._x)/6;
    	}
    }
    you only had the < backwards. You needed >.
    Last edited by Ralgoth; 09-11-2006 at 09:05 AM.
    Search first, asked questions later.

  3. #3
    Grandmaster Flash
    Join Date
    Apr 2004
    Location
    Edinburgh, Scotland
    Posts
    139
    the 'and' keyword is deprecated.

    Try using '&&'

    eg.
    if (_root._ymouse > 50 && _root._ymouse < 150 && _root._xmouse >-10 && _root._xmouse <900)

    I'm not sure where the -200 that you mentioned comes in, but play with the vals and see if you have any luck
    If it ain't broke, don't fix it.

  4. #4
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    only in Flash 8 and later is the 'and' removed. MX 2004 it should be fine, though && is a better practice.
    Search first, asked questions later.

  5. #5
    Grandmaster Flash
    Join Date
    Apr 2004
    Location
    Edinburgh, Scotland
    Posts
    139
    Ralgoth - I think we posted at the same time. What you suggested looks like a solution.

    The values might need to be tweaked. I'd also suggest tracing the values of _xmouse and _ymouse in your enterframe function to debug it.

    HTH
    If it ain't broke, don't fix it.

  6. #6
    user in A minor
    Join Date
    Jan 2005
    Location
    finland
    Posts
    121
    hmm. *scratches head* ralgoth, it works, but not quite as it should. now, when the menu_mc reaches the limit point (the limit point, geedubb, is what i mean with -200: at that x value the right end of the menu has reached the main movie's right side limit) the menu_mc just gets stuck there and won't scroll back any more. i need it to scroll within the given limits. i tried this already, btw. any other ideas...?

  7. #7
    user in A minor
    Join Date
    Jan 2005
    Location
    finland
    Posts
    121
    here's the fla to make things more clear
    Attached Files Attached Files

  8. #8
    user in A minor
    Join Date
    Jan 2005
    Location
    finland
    Posts
    121
    oops, sorry, forgot to mention:it's in flash 8

  9. #9
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    Here.. this may be a bit more simple than you're looking for, but it works. It basically will detect if the mouse is to the left or right of the center stage, and then scroll the menu accordingly.
    Code:
    _root.onEnterFrame = function() {
    	if (_root._ymouse>menu_mc._y-25 && _root._ymouse<menu_mc._y+menu_mc._height+25) {
    		xdist = (Stage.width/2)-Math.sqrt((_xmouse-(Stage.width/2))*(_xmouse-(Stage.width/2)));
    		xdist = Math.round(xdist/20);
    		if (menu_mc._x+menu_mc._width>Stage.width && _root._xmouse>Stage.width/2) {
    			menu_mc._x += (((menu_mc._width-Stage.width)*-1)-menu_mc._x)/xdist;
    			pointer_mc._x += ((Stage.width/2+100)-pointer_mc._x)/xdist;
    			if (menu_mc._x+menu_mc._width<=Stage.width) {
    				menu_mc._x = (menu_mc._width-Stage.width)*-1;
    			}
    		} else if (menu_mc._x<0 && _root._xmouse<Stage.width/2) {
    			menu_mc._x += (0-menu_mc._x)/xdist;
    			pointer_mc._x += ((Stage.width/2-100)-pointer_mc._x)/xdist;
    			if (menu_mc._x>0) {
    				menu_mc._x = 0;
    			}
    		}
    	}
    };
    Search first, asked questions later.

  10. #10
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    I've never tried to put together a smooth scrolling menu, so the math I'm sure could be adjusted. If you want to make it a little less choppy, rather than having the menu scroll if it's past the center, you could make it scroll if it's near the edges. something like...

    Code:
    _root.onEnterFrame = function() {
    	if (_root._ymouse>menu_mc._y-25 && _root._ymouse<menu_mc._y+menu_mc._height+25) {
    		xdist = (Stage.width/2)-Math.sqrt((_xmouse-(Stage.width/2))*(_xmouse-(Stage.width/2)));
    		if (menu_mc._x+menu_mc._width>Stage.width && _root._xmouse>Stage.width/2+(Stage.width/4)) {
    			menu_mc._x += (((menu_mc._width-Stage.width)*-1)-menu_mc._x)/xdist;
    			pointer_mc._x += ((Stage.width/2+100)-pointer_mc._x)/xdist;
    			if (menu_mc._x+menu_mc._width<=Stage.width) {
    				menu_mc._x = (menu_mc._width-Stage.width)*-1;
    			}
    		} else if (menu_mc._x<0 && _root._xmouse<Stage.width/2-(Stage.width/4)) {
    			menu_mc._x += (0-menu_mc._x)/xdist;
    			pointer_mc._x += ((Stage.width/2-100)-pointer_mc._x)/xdist;
    			if (menu_mc._x>0) {
    				menu_mc._x = 0;
    			}
    		}
    	}
    };
    Search first, asked questions later.

  11. #11
    user in A minor
    Join Date
    Jan 2005
    Location
    finland
    Posts
    121
    hi there, ralgoth!
    so many curvy roads all lead to rome, don't they i modified your first code a bit, and it's close to perfect ( i just changed the pointer_mc bits so it follows the mouse better, and as i use fixed screen size, will also change the Stage.width's into numbers)
    Code:
    _root.onEnterFrame = function() {
    	if (_root._ymouse>menu_mc._y-25 && _root._ymouse<menu_mc._y+menu_mc._height+25) {
    		xdist = (Stage.width/2)-Math.sqrt((_xmouse-(Stage.width/2))*(_xmouse-(Stage.width/2)));
    		xdist = Math.round(xdist/20);
    		if (menu_mc._x+menu_mc._width>Stage.width && _root._xmouse>Stage.width/2) {
    			menu_mc._x += (((menu_mc._width-Stage.width)*-1)-menu_mc._x)/xdist;
    			pointer_mc._x += (_xmouse-pointer_mc._x)/6;
    			if (menu_mc._x+menu_mc._width<=Stage.width) {
    				menu_mc._x = (menu_mc._width-Stage.width)*-1;
    			}
    		} else if (menu_mc._x<0 && _root._xmouse<Stage.width/2) {
    			menu_mc._x += (0-menu_mc._x)/xdist;
    			pointer_mc._x += (_xmouse-pointer_mc._x)/6;
    			if (menu_mc._x>0) {
    				menu_mc._x = 0;
    			}
    		}
    	}
    };
    this one works almost ok, but the thing often pauses to think for a good few secs until it moves again, i suppose because there's a lot of stuff for flash to chew upon. or...? it's not a catastrophy, but sometimes the pauses seem reeeeally long. anyway, ralgoth, the result sure looks better than all my efforts so far, so thanks for the tips already!

    but, as the code i started with, was a lot simpler, i suppose there has to be an easier way to do this. it'd sure be nice to see that, wouldn't it! so, anyone, please come to our rescue..?

  12. #12
    user in A minor
    Join Date
    Jan 2005
    Location
    finland
    Posts
    121
    addition to the previous: i noticed that once the menu has reached its given limits, you actually have to click the swf for it to scroll again. is there any way to fix this..?


    ---nnnnaaaah, correction, u don't have to click it, i was just too hasty. but it does pause often. wonder why...
    Last edited by mrk13; 09-11-2006 at 11:07 AM. Reason: too busy me.

  13. #13
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    you should check out Lee Brimlow's "Creating 3D carousels" tutorial at http://www.gotoandlearn.com. It might not be exactly what you're trying to do, but it'll probably give you a few good ideas.
    Search first, asked questions later.

  14. #14
    user in A minor
    Join Date
    Jan 2005
    Location
    finland
    Posts
    121
    allright, thanks for the advice! by now i've managed to get the thingie working quite nicely.... you've been a big help. cheers!

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