A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Drag/resizable square

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

    Drag/resizable square

    Hi all,

    I'm working on an application to play around with images. In which I want to make something like the selection tool in Photoshop. What I want to do is, once the selection tool is selected, for users to click anywhere on the image, this way they start the selection square. The square automatically resizes along with the mouse movement. Once they release the mouse button the square will be fixed and not resize anymore. I've been playing around with it but I can't get it to work. This is what I have;

    Code:
    this.attachMovie("drag_square", "drag_square", 1000000);
    _root.drag_square._visible = false;
    _root.child_holder.onMouseDown = function() {
    	_root.drag_square._width =0;
    	_root.drag_square._height =0;
    	_root.drag_square._visible = true;
    	_root.drag_square._x = _root.child_holder._x+_root.child_holder._xmouse;
    	_root.drag_square._y = _root.child_holder._y+_root.child_holder._ymouse;
    };
    _root.child_holder.onMouseMove = function() {
    	_root.drag_square._width = _root._xmouse-_root.drag_square._x;
    	_root.drag_square._height = _root._ymouse-_root.drag_square._y;
    };
    The problems are;

    The square starts anywhere on stage, eventhough I set _root.child_holder.onMouseDown and not Stage.onMouseDown or something.

    And the function continues after releasing the mousebutton. is there a function to use in stead of _root.child_holder.onMouseMove, something like
    _root.child_holder.onWhileMouseDown?

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

  2. #2
    Can't Re-Member madzigian's Avatar
    Join Date
    Apr 2004
    Location
    Boston MA
    Posts
    2,662
    maybe this will help you
    Please DO NOT PM me simply for individual help. Post in the public forums...that's what they are for, and they allow others to benefit as well. - Thx
    OS X 10.3.9 || Flash MX04 Pro
    | del.icio.us || furl || Helpful Source Files || Free Pixel Fonts |

  3. #3
    Angkor-What? Gekke_Hollander's Avatar
    Join Date
    Jun 2000
    Location
    Netherlands
    Posts
    234
    Thanx alot! It helped a lot... my code is now:

    Code:
    this.attachMovie("drag_square", "drag_square", 1000000);
    _root.drag_square._visible = false;
    
    _root.child_holder.onPress = function() {
    	_root.drag_square._width =0;
    	_root.drag_square._height =0;
    	_root.drag_square._visible = true;
    	_root.drag_square._x = _root.child_holder._x+_root.child_holder._xmouse;
    	_root.drag_square._y = _root.child_holder._y+_root.child_holder._ymouse;
    	this.onMouseMove = function() {
    	_root.drag_square._width = _root._xmouse-_root.drag_square._x;
    	_root.drag_square._height = _root._ymouse-_root.drag_square._y;
    };
    };
    _root.child_holder.onRelease = _root.child_holder.onReleaseOutside = function() {
    	delete this.onMouseMove;
    };
    And it works perfectly! I didn't know I could add functions like onPress and stuff, thought only onMouseDwon, onMouseUp, onMouseMove were posible. Also, delete this.onMouseMove; is something I didn't think of!

    Thanx mate!

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

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