A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: "onMouseMove" HELP!

  1. #1
    Member
    Join Date
    Apr 2008
    Posts
    44

    "onMouseMove" HELP!

    Hello,

    I have a panning movieclip (Main_mc) that reacts on MouseMove.

    Inside Main_mc is a movie clip with a button (btn_A).

    I want Main_mc to move when I rollover btn_A (it already works)

    but since my mouse is still over Main_mc, when I roll-over btn_A, Main-mc will move to a specific location but right after it will shift because the
    on MouseMove panning script on the main timeline interferes.

    ????

    is there a way that I can disable the panning script on the main timeline as I rollover btn_A (which is inside Main_mc) and then enable on rollOut.

    please help it's almost there but not quite

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Maybe try something like this...

    Create a new variable -- canPan = true;

    In the rollover btn_A code set canPan equal to false.
    In the rollout btn_A code set canPan equal to true.

    In the MouseMove script add a check to see if canPan is true.

    if (canPan == true){
    //... panning script is here
    }

  3. #3
    Member
    Join Date
    Apr 2008
    Posts
    44
    Hi Im sorry to impose, but im kind of clueless with actionscript so I'm not sure where to create new variable? here's my panning script

    this.onMouseMove = function() {
    constrainedMove(MC, 4, 1);
    };
    function constrainedMove(target:MovieClip, speed:Number, dir:Number) {
    var mousePercent:Number = _xmouse/Stage.width;
    var mSpeed:Number;
    if (dir == -1) {
    mSpeed = 1-mousePercent;
    } else {
    mSpeed = mousePercent;
    }
    target.destX = Math.round(-((target._width-Stage.width)*mSpeed));
    target.onEnterFrame = function() {
    if (target._x == target.destX) {
    delete target.onEnterFrame;
    } else {
    target._x += Math.ceil((target.destX-target._x)*(speed/100));
    }
    };
    }

  4. #4
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Maybe you can adapt this to what you are trying to do...

    Code:
    this.onMouseMove = function() {
    	constrainedMove(MC, 4, 1);
    };
    var canPan:Boolean = true;
    function constrainedMove(target:MovieClip, speed:Number, dir:Number) {
    	var mousePercent:Number = _xmouse / Stage.width;
    	var mSpeed:Number;
    	if (dir == -1) {
    		mSpeed = 1 - mousePercent;
    	} else {
    		mSpeed = mousePercent;
    	}
    	target.destX = Math.round(-((target._width - Stage.width) * mSpeed));
    	target.onEnterFrame = function() {
    		if (target._x == target.destX) {
    			delete target.onEnterFrame;
    		} else {
    			if (canPan) {
    				target._x += Math.ceil((target.destX - target._x) * (speed / 100));
    			} else {
    				delete target.onEnterFrame;
    			}
    		}
    	};
    }
    MC.btn_A.onRollOver = function() {
    	canPan = false;
    	// not knowing what your code is doing, just moved it to arbitary _x location
    	MC._x = 50;
    	// need some event to allow panning to resume
    	// not know how your code is set up, used an onPress
    	this.onPress = function() {
    		canPan = true;
    	};
    };

  5. #5
    Member
    Join Date
    Apr 2008
    Posts
    44
    OK im not doing something right....

    on (Release) {

    canPan = false;


    // mc move script

    import mx.transitions.Tween;

    _root.MC.onEnterFrame = function() {

    var tw:Tween = new Tween(_root.MC, "_x", Strong.easeIn, _root.MC._x, -688, .25, true);}



    }

    is this not correct?

    Thanks a lot, i really appreciate your help

  6. #6
    :
    Join Date
    Dec 2002
    Posts
    3,518
    I only have Flash MX2004, can you post a simplified version of your .fla?

  7. #7
    Member
    Join Date
    Apr 2008
    Posts
    44
    hi


    * so I was thinking if only I can disable that action layer when on (release)
    then I'm in good shape, or maybe not...



    http://www.muellerdesign.com/aftp/testfolder/

    file: SFcharm

    that'd be great if you can help me...
    thanks a lot

  8. #8
    :
    Join Date
    Dec 2002
    Posts
    3,518
    I only have Flash MX 2004, so I couldn't open your file.
    If you can't post a MX2004 version, then maybe this is something you can adapt...
    Last edited by dawsonk; 06-25-2008 at 05:38 PM.

  9. #9
    Member
    Join Date
    Apr 2008
    Posts
    44

    on RollOut

    Hi, Thank you so much!
    so animation is so far so good I just need to tweak something...

    you can go ahead and view the animation here:
    http://www.muellerdesign.com/aftp/te...ate-Jv1.0.html

    so on the first photo (i've only tested the other code on this photo):

    - click on the upper half (hit area) and a movie clip loads...
    on your code it's an onPress event that it's gonna go back to the scrolling screen.

    I want it to remove the loaded movie clip onRollOut (lower half, non hit area) which it kind of does but then the scrolling gets funky.

    Roll from 1st photo hit area to 2nd photo and the scrolling stops. I don't know why it does that?!
    Whenever you go from 1st photo hit area to outside of it the scrolling stops and you kinda have to move your mouse around for it to resume.

    I kinda tweaked your code that's why it's messing up, will you take another look pls? I'm pretty sure this isnt so complicated anymore.


    thank you!!!


    // your code

    stop();
    var _MAIN:MovieClip = this;
    var isSelected:MovieClip = null;
    var canPan:Boolean = true;
    MC._x = locX;
    //
    function constrainedMove(target:MovieClip, speed:Number, dir:Number) {
    var mousePercent:Number = _xmouse/bg._width;
    var mSpeed:Number = mousePercent*dir;
    target.destX = Math.round(-((target._width-bg._width)*mSpeed));
    target.onEnterFrame = function() {
    if (target._x == target.destX || target._x>0 || target._x<bg._width-target._width) {
    delete target.onEnterFrame;
    if (target._x>0) {
    target._x = 0;
    } else if (target._x<bg._width-target._width) {
    target._x = bg._width-target._width;
    }
    } else if (canPan) {
    target._x += Math.ceil((target.destX-target._x)*(speed/100));
    } else {
    delete target.onEnterFrame;
    }
    };
    }


    // load movie clip code
    function doPress(btn) {
    canPan = !canPan;
    if (!canPan) {
    isSelected = _MAIN.attachMovie(btn._name, btn._name, 1, {_x:0, _y:0});

    } else {
    isSelected.removeMovieClip();
    MC._x = locX=0-(btn._x);

    }
    }


    MC.btn_A.onPress = function() {
    doPress(this);
    };

    //this part doesnt really work smoothly

    MC.btn_A.onRollOut = function() {
    canPan = !canPan;
    !canPan == true
    isSelected.removeMovieClip();

    };




    MC.btn_B.onPress = function() {
    doPress(this);
    };
    MC.btn_C.onPress = function() {
    doPress(this);
    };
    MC.btn_D.onPress = function() {
    doPress(this);
    };
    _MAIN.onMouseMove = function() {
    constrainedMove(MC,4,1);
    };




    thanks again.

  10. #10
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Instead of adding code as part of the MC.btn's onRollOver; try something like the following...
    Code:
    function doPress(btn) {
    	canPan = !canPan;
    	if (!canPan) {
    		MC._x = locX = 0 - (btn._x);
    		isSelected = _MAIN.attachMovie(btn._name, btn._name, 1, {_x:25, _y:0});
    		isSelected.btnMore.onPress = function() {
    			_MAIN.gotoAndStop(btn._name);
    			isSelected.removeMovieClip();
    			_MAIN.btnReturn.onPress = function() {
    				_MAIN.gotoAndStop("home");
    			};
    		};
    		isSelected.onEnterFrame = function() {
    			if (this.hitTest(_xmouse, _ymouse, true)) {
    				this.isOver = true;
    			} else if (this.isOver) {
    				this.removeMovieClip();
    				canPan = true;
    			}
    		};	
    	} else {
    		isSelected.removeMovieClip();
    	}
    }

  11. #11
    Member
    Join Date
    Apr 2008
    Posts
    44
    Hi!

    first of all thanks very much for your help.


    the animation has been working well BUT, i need it to do something else,

    I want the main movie clip to scroll and then loop when the mouse is off the stage but then on mouse over move with it and all (this part works already)

    I got a script of the infinite scroll and it works
    The mouseOver script you gave me worked well

    now I need them to work together! what to do??

    i was hoping it works this way:
    http://ts.rtvpix.com/tour/RS/tour.vi...7001-BNVX7A-01

    like a virtual tour without the 360 aspect, just an infinite loop.
    it scrolls independently, but moves on MouseMove

    here's my script:

    stop();

    //scroll actionscript


    var mySpeed:Number;
    var myCount:Number = 0;
    var Scroll:Boolean = true;
    var keepMoving:Boolean;
    keepMoving = true;
    mySpeed = 1;


    _root.onEnterFrame = function() {
    //onMouseOut = function () {

    // CHECK FOR RESTART
    if (myCount>=4115.6) {
    //686.9

    _root.MC._x = -688;
    myCount = 688;

    } else {

    // CHECK FOR MOVEMENT OF SCROLLING MOVIE
    if (keepMoving) {
    _root.MC._x -= mySpeed;
    myCount += mySpeed;
    //}
    }
    }
    };
    //stop();



    var _MAIN:MovieClip = this;
    var isSelected:MovieClip = null;
    var canPan:Boolean = true;
    MC._x = locX;
    //
    function constrainedMove(target:MovieClip, speed:Number, dir:Number) {
    var mousePercent:Number = _xmouse/bg._width;
    var mSpeed:Number = mousePercent*dir;
    target.destX = Math.round(-((target._width-bg._width)*mSpeed));
    target.onEnterFrame = function() {
    if (target._x == target.destX || target._x>0 || target._x<bg._width-target._width) {
    delete target.onEnterFrame;
    if (target._x>0) {
    target._x = 0;
    } else if (target._x<bg._width-target._width) {
    target._x = bg._width-target._width;
    }
    } else if (canPan) {
    target._x += Math.ceil((target.destX-target._x)*(speed/100));
    } else {
    delete target.onEnterFrame;
    }
    };
    }



    function doPress(btn) {

    canPan = !canPan;
    if (!canPan) {
    keepMoving = false;
    gotoAndPlay(3);
    _MAIN.info_A.buttonA.onRollOut = function() {
    _MAIN.gotoAndStop("home");
    MC._x = locX=0-(_root.info_A.buttonA._x);
    };
    } else {
    keepMoving = true;


    }
    }


    function doPressB(btn) {

    canPan = !canPan;
    if (!canPan) {
    keepMoving = false;
    gotoAndPlay(4);
    _MAIN.info_B.buttonB.onRollOut = function() {
    _MAIN.gotoAndStop("home");
    MC._x = locX=0-(_MAIN.info_B.buttonB._x);

    };
    } else {
    keepMoving = true;


    }
    }

    function doPressC(btn) {

    canPan = !canPan;
    if (!canPan) {
    keepMoving = false;
    gotoAndPlay(5);
    _MAIN.info_C.buttonC.onRollOut = function() {
    _MAIN.gotoAndStop("home");
    MC._x = locX=0-(_MAIN.info_C.buttonC._x);
    };
    } else {
    keepMoving = true;


    }
    }

    function doPressD(btn) {

    canPan = !canPan;
    if (!canPan) {
    keepMoving = false;
    gotoAndPlay(6);
    _MAIN.info_D.buttonD.onRollOut = function() {
    _MAIN.gotoAndStop("home");
    MC._x = locX=0-(_MAIN.info_D.buttonD._x);
    };
    } else {
    keepMoving = true;

    }
    }

    function doPressE(btn) {

    canPan = !canPan;
    if (!canPan) {
    keepMoving = false;
    gotoAndPlay(7);
    _MAIN.info_E.buttonE.onRollOut = function() {
    _MAIN.gotoAndStop("home");
    MC._x = locX=0-(_MAIN.info_E.buttonE._x);
    };
    } else {
    keepMoving = true;


    }
    }



    //white bar visibility

    _root.MC.P1_info._alpha = 0;
    _root.MC.P2_info._alpha = 0;
    _root.MC.P3_info._alpha = 0;
    _root.MC.P4_info._alpha = 0;
    _root.MC.P5_info._alpha = 0;




    MC.btn_A.onRollOver = function() {
    doPress(this);
    };

    MC.btn_B.onRollOver = function() {
    doPressB(this);
    };

    MC.btn_C.onRollOver = function() {
    doPressC(this);
    };

    MC.btn_D.onRollOver = function() {
    doPressD(this);
    };
    MC.btn_E.onRollOver = function() {
    doPressE(this);
    };


    _MAIN.onMouseMove = function() {
    constrainedMove(MC,4,1);
    };

  12. #12
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Maybe try something like this...

    Code:
    var myDir = 1;
    function autoMove(target:MovieClip, speed:Number) {
    	target.onEnterFrame = function() {
    		if (target._x > 0) {
    			myDir = -1;
    		} else if (target._x < bg._width - target._width) {
    			myDir = 1;
    		}
    		target._x += (speed * myDir);
    	};
    }
    _MAIN.onMouseMove = function() {
    	if (bg.hitTest(_xmouse, _ymouse, false)) {
    		constrainedMove(MC, 4, 1);
    	} else {
    		autoMove(MC, 2);
    	}
    };

  13. #13
    Member
    Join Date
    Apr 2008
    Posts
    44
    Hi,

    It's not really working for me
    sorry not really a coder im a full pledged print designer

    anyway so as I have explained already this is what im hoping to accomplish.

    -mouse is NOT OVER the stage: it will scroll on it's own and loop.
    -mouse is OVER: it will Pan (you gave me this excellent code!)
    -if i decide to remove my mouse again after I panned: It will continue scrolling on it's own.

    I kinda get the code and what you're making it do, but in the context of the previous code I cant integrate it.

    FAVOR PLS:

    I attached this file, you gave this to me, it has the panning code that I was able to tailor. can you integrate a code that makes it scroll when mouse is not over and pan when mouse is over.... It'll be easier for me to understand.


    thank you very much for your help!!!
    Attached Files Attached Files

  14. #14
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Added the code from above, so if the mouse is outside the stage (not over the 'bg' movie clip which covers the stage), the 'mc' scrolls. Didn't change the panning function.
    Last edited by dawsonk; 08-21-2008 at 10:07 AM.

  15. #15
    Member
    Join Date
    Apr 2008
    Posts
    44
    Hi,

    it doesnt work. am I missing anything?

  16. #16
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Sorry, I only tested it the IDE, you are right it does NOT work in a web page, as flash doesn't have a built-in way to track the mouse outside of the swf. Here's a link explaining a work around for when the mouse is outside of the swf. http://www.actionscript.org/forums/s....php3?t=136109

    HTH

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