A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: using hitTest or just startDrag?

  1. #1
    Senior Member
    Join Date
    Sep 2002
    Posts
    136

    using hitTest or just startDrag?

    hello, i was under the impression that you need to do a hit test to drag a specific object around. matter of fact all the books ive looked at and all the tutorials say use code similar to below:

    onClipEvent(mouseDown){
    if(_root.dragmovie02.hitTest(_root._xmouse, _root._ymouse, true)){
    this.startDrag(false);
    }
    }
    onClipEvent(mouseUp){
    if(_root.dragmovie02.hitTest(_root._xmouse, _root._ymouse, true)){
    this.stopDrag();

    however, i just found a tutorial that uses the following code. please note: i am using on() events (which i thought could only be used for buttons) on a movie clip. there is no button being used. its all attached to the movie clip:

    on(press){
    this.startDrag();
    }

    on(release){
    this.stopDrag();
    }



    now my question is, why does everyone use the hitTest.

  2. #2
    Senior Member
    Join Date
    Sep 2002
    Posts
    136
    heres the .fla
    also please note: the hitTest way of doing it seems to BREAK if you drag the object really fast. the object seems to stick to the cursor even though you its suppose to stopDrag....try it out. the on(release) way of doing it never breaks.

    also, do you know how to prevent the object from sticking to the cursor?

    thanks.
    Attached Files Attached Files

  3. #3
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    fix the hitTest with-
    code:

    onClipEvent(mouseDown){
    if(this.hitTest(_root._xmouse, _root._ymouse, true)){
    this.startDrag(false);
    }
    }
    onClipEvent(mouseUp){
    this.stopDrag();
    }

    onClipEvent(enterFrame){
    updateAfterEvent();
    }


    applying on() events to movieclips is new to MX,
    this can also be applied to the clip instance from the main timeline
    code:

    dragmovie.onPress = function(){
    this.startDrag(true);
    }

    dragmovie.onRelease = function(){
    this.stopDrag();
    }



    hth

  4. #4
    Senior Member
    Join Date
    Sep 2002
    Posts
    136
    thank you. can you tell me what is the most common way to make the movie clip draggable?

    also, can you tell me what the

    onClipEvent(enterFrame){
    updateAfterEvent();
    }

    is for?

    also, if im directly referencing the movie clip by _root.dragmovie.hitTest why would this.hitTest work better? wouldnt that be the same? either way right?

  5. #5
    Senior Member
    Join Date
    Sep 2002
    Posts
    136
    updateAfterEvent REALLY solves that sticky movieclip problem but can you tell my WHY. shouldnt the code work regardless? if i tell flash to STOPDRAG when mouse is up then why doesnt always do it? is this a bug?

    also, i tried the dragmovie.onPress = function
    exactly as you have it but it doesnt work. i applied it to a movie clip that sits on the main timeline. heres my code.


    dragmovie03.onPress = function(){
    this.startDrag(true);
    }

    dragmovie03.onRelease = function(){
    this.stopDrag();
    }


    edit to update:
    i got the function way of doing it working properly, i had the code on the movie clip instead of the main time line.
    Last edited by beatle888; 05-17-2003 at 08:16 PM.

  6. #6
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    your problem was here -

    onClipEvent(mouseUp){
    if(_root.dragmovie02.hitTest(_root._xmouse, _root._ymouse, true)){ this.stopDrag(); }}

    this code says - when the mouse is released, ONLY if the mouse is still within the bounds of dragmovie2, stop dragging.

    if you move the mouse too fast, the above argument was not being met, and the "sticky" drag occurs,

    whereas - onClipEvent(mouseUp){ this.stopDrag(); }

    stops the drag, regardless of where the mouse is positioned,

    hth

  7. #7
    Senior Member
    Join Date
    Sep 2002
    Posts
    136
    of course.

    thank you very much.

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