A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: startDrag or customStartDrag???

  1. #1
    Angkor-What? Gekke_Hollander's Avatar
    Join Date
    Jun 2000
    Location
    Netherlands
    Posts
    234

    startDrag or customStartDrag???

    Just pondering...

    I've been working on a project for a while. My first big one in Flash for over a year... and I ran into something funny... well to me it was

    When I use startDrag() to make a mc follow the mouse it works ok. The mc follows the mouse as long as the mouse is over the stage. Moving the mouse outside of the stage pauzes the dragging action untill the mouse is within the stage boundries again...

    But when I do something like:
    Code:
    // in case of lock to center
    _root.draggable_mc.onMouseMove = function()
    {
    _root.draggable_mc._x = _root._xmouse-(_root.draggable_mc._width/2);
    _root.draggable_mc._y = _root._ymouse-(_root.draggable_mc._height/2);
    }
    
    // in case of not locking to center but to the point clicked
    _root.draggable_mc.onPress = function()
    {
    _root.dragMc_x_mouseOffset = _root._xmouse-_root.draggable_mc._x;
    _root.dragMc_y_mouseOffset = _root._ymouse-_root.draggable_mc._y;
    }
    
    _root.draggable_mc.onMouseMove = function()
    {
    _root.draggable_mc._x = _root._xmouse_root.dragMc_x_mouseOffset;
    _root.draggable_mc._y = _root._ymouse_root.dragMc_y_mouseOffset;
    }
    Imagine the code you'll need with a constrained set... believe me, it's quiet long. So why doing this? The mc keeps on following the mouse even when the mouse is out of the stage boundries... which can be very usefull in some cases.

    But because this will need quiet some coding I was wondering if this same effect is possible with startDrag. Ofcourse not in the standard way but maybe with some different settings...

    Like I said, just pondering

    cheers
    MX 2004 Pro - Oops I did it again!!!
    SWF, it's a journey... not a destination

  2. #2
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    your code doesn't work for me.
    neither of the two code ideas (as far as i can see) work outside the stage area - dragging stops .
    use updateAfterEvent() for mouseMove - makes for a much smoother drad

  3. #3
    Angkor-What? Gekke_Hollander's Avatar
    Join Date
    Jun 2000
    Location
    Netherlands
    Posts
    234
    Sorry, was a bit sloppy!

    Here's the code + an example:

    Code:
    // regular drag with constrain & no lock center
    _root.drag_square.onPress = function() {
    	ds_t = _root.constrain_field._y;
    	ds_l = _root.constrain_field._x;
    	ds_r = (_root.constrain_field._x+_root.constrain_field._width)-_root.drag_square._width;
    	ds_b = (_root.constrain_field._y+_root.constrain_field._height)-_root.drag_square._height;
    	this.startDrag(false, ds_l, ds_t, ds_r, ds_b);
    	this.onMouseMove = function() {
    		updateAfterEvent();
    	}
    };
    _root.drag_square.onRelease = _root.drag_square.onReleaseOutside=function () {
    	this.stopDrag();
    	updateAfterEvent();
    };
    And here's my work around:

    Code:
    // custom drag with constrain & no lock center
    _root.drag_square.onPress = function() {
    	_root.ds_x_mouseOffset = _root._xmouse-_root.drag_square._x;
    	_root.ds_y_mouseOffset = _root._ymouse-_root.drag_square._y;
    	ds_t = _root.constrain_field._y;
    	ds_l = _root.constrain_field._x;
    	ds_r = (_root.constrain_field._x+_root.constrain_field._width)-_root.drag_square._width;
    	ds_b = (_root.constrain_field._y+_root.constrain_field._height)-_root.drag_square._height;
    	this.onMouseMove = function() {
    		new_drag_square_x = _root._xmouse-_root.ds_x_mouseOffset;
    		if (new_drag_square_x<ds_l) {
    			new_drag_square_x = ds_l;
    		} else if (new_drag_square_x>ds_r) {
    			new_drag_square_x = ds_r;
    		}
    		_root.drag_square._x = new_drag_square_x;
    		new_drag_square_y = _root._ymouse-_root.ds_y_mouseOffset;
    		if (new_drag_square_y<ds_t) {
    			new_drag_square_y = ds_t;
    		} else if (new_drag_square_y>ds_b) {
    			new_drag_square_y = ds_b;
    		}
    		_root.drag_square._y = new_drag_square_y;
    		updateAfterEvent();
    	};
    };
    _root.drag_square.onRelease = _root.drag_square.onReleaseOutside=function () {
    	delete this.onMouseMove;
    	updateAfterEvent();
    };
    What do you think? the second code works even if the mouse is outside the swf/stage....

    Cheers
    Attached Files Attached Files
    MX 2004 Pro - Oops I did it again!!!
    SWF, it's a journey... not a destination

  4. #4
    Angkor-What? Gekke_Hollander's Avatar
    Join Date
    Jun 2000
    Location
    Netherlands
    Posts
    234
    I serached on other forums for any posts on this topic but to no avail... guess the same result isn't possible with startDrag...

    Cheers
    MX 2004 Pro - Oops I did it again!!!
    SWF, it's a journey... not a destination

  5. #5
    Junior Member
    Join Date
    Oct 2003
    Location
    Crestview, Fl
    Posts
    7

    how would you apply this with a zoom feature?

    I have a map that i'm working on that basically sets up like this:
    map inside mask, when zoomed you see a portion of the map through
    the mask window, map is draggable (with inertia) and the problem is I cannot
    keep the map from crossing a preset "ZoomMargin" mc on the root timeline.

    visual:
    http://dev.emeraldcoast.com/seatown...t/flashMap.html

    Any help would be appreciated

    Thanks

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