Skip to main content
Known Participant
June 10, 2009
Answered

onreleaseoutside = ?

  • June 10, 2009
  • 2 replies
  • 795 views

onrelease = MOUSE_UP ?

onreleaseoutside = ??

or both is = to MOUSE_UP?

Here is my problem , when i start to click and drag , sometimes when i let go , it will still be .startDrag(); and bigger in size.Can you guys tell me where is my problem?Frame 1 will be the original symbol , frame 2 will be colour changed and frame 3 will be bigger.

stop();

this.addEventListener(MouseEvent.MOUSE_OVER , this_over);

this.addEventListener(MouseEvent.MOUSE_OUT, this_out);

this.addEventListener(MouseEvent.MOUSE_DOWN , this_down);

this.addEventListener(MouseEvent.MOUSE_UP , this_up);

function this_over(Event:MouseEvent):void

{

     if(this.currentFrame == 1){

          this.gotoAndStop(2);

     }

}

function this_out(Event:MouseEvent):void

{

     if(this.currentFrame == 2){

          this.gotoAndStop(1);

     }

}

function this_down(Event:MouseEvent):void

{

     if(this.currentFrame == 2){

          this.gotoAndStop(3);

          startDrag();}

      if(this.currentFrame ==1){

          this.gotoAndStop(3);

          startDrag();}

}


function this_up(Event:MouseEvent):void

{

     stopDrag();

     this.gotoAndStop(1);

}

This topic has been closed for replies.
Correct answer Rothrock

See that is what I mean. I don't really know what you are talking about. What does, "Actually my main concern is when i released the mouse , the mouse will still be in frame 3 and dragging without me clicking on it which is the same function as MOUSE_DOWN" mean?

Why would when you release the mouse be the same as MOUSE_DOWN?

But anyways, there are several things that I don't think should be working anyways.

First, since there is an Event class you shouldn't give your parameter the same name. Generally I just use a lower case "e" but a lot of other folks use "event" -- notice that a lower case initial letter makes all the difference.

The next thing is that you would then generally get the item clicked on by referencing the target or currentTarget of the event parameter. So e.target or e.currentTarget. I don't know why it works at all because "this" should refer to the timeline you are on not the item that is being clicked. So the whole thing should be moving. But then again you put your addEventListeners on "this" too. So my guess is that you put the code on the timeline inside the movieclip instead of on the timeline where the clips are? I guess you can do that, but it is generally not the best practice.

Finally not quite sure why you chose to prefix the function names with "this_" but that can make it kind of awkward and confusing. It kind of mixes them up with the reserved word "this." So I would suggest some kind of better name. So probably something more like this:

function overClip(e:MouseEvent):void

{

     if(e.target.currentFrame == 1){

         e.target.gotoAndStop(2);

     }

}

Okay so I'm confused by all the stuff above. But I think you are still asking how to releaseOutside. To register an event to the stage you would do this:

stage.addEventListener(MouseEvent.MOUSE_UP,clipUp);

Don't add that and keep your existing code. You only need one. In other words you don't need a MOUSE_UP listener on both your clip and the stage -- you only need the one. So if your button or whatever it is is called clip you could have code something like this:

var curDrag:MovieClip;

clip.addEventListener(MouseEvent.MOUSE_DOWN,clipPress);

function clipPress(e:MouseEvent):void{

   stage.addEventListener(MouseEvent.MOUSE_UP,clipRelease);

   curDrag=e.target;

   curDrag.gotoAndStop(3);

   curDrag.startDrag();

}

function clipRelease(e:MouseEvent):void{

   stage.removeEventListener(MouseEvent.MOUSE_UP,clipRelease);

   curDrag.gotoAndStop(1);

   stopDrag();

}

I think that is what you are after.

2 replies

Inspiring
June 11, 2009

Your question isn't really clear, but I think you are asking what is the AS3 equivalent of onReleaseOutside?

The general trick is to register the MouseEvent.MOUSE_UP to the stage. Then if the target isn't the same as the one clicked you know that it has been released outside.

Known Participant
June 11, 2009

hmm.. sorry rothrock. but how do i register the MouseEvent.MOUSE_UP to the stage?? Actually my main concern is when i released the mouse , the mouse will still be in frame 3 and dragging without me clicking on it which is the same function as MOUSE_DOWN.

RothrockCorrect answer
Inspiring
June 11, 2009

See that is what I mean. I don't really know what you are talking about. What does, "Actually my main concern is when i released the mouse , the mouse will still be in frame 3 and dragging without me clicking on it which is the same function as MOUSE_DOWN" mean?

Why would when you release the mouse be the same as MOUSE_DOWN?

But anyways, there are several things that I don't think should be working anyways.

First, since there is an Event class you shouldn't give your parameter the same name. Generally I just use a lower case "e" but a lot of other folks use "event" -- notice that a lower case initial letter makes all the difference.

The next thing is that you would then generally get the item clicked on by referencing the target or currentTarget of the event parameter. So e.target or e.currentTarget. I don't know why it works at all because "this" should refer to the timeline you are on not the item that is being clicked. So the whole thing should be moving. But then again you put your addEventListeners on "this" too. So my guess is that you put the code on the timeline inside the movieclip instead of on the timeline where the clips are? I guess you can do that, but it is generally not the best practice.

Finally not quite sure why you chose to prefix the function names with "this_" but that can make it kind of awkward and confusing. It kind of mixes them up with the reserved word "this." So I would suggest some kind of better name. So probably something more like this:

function overClip(e:MouseEvent):void

{

     if(e.target.currentFrame == 1){

         e.target.gotoAndStop(2);

     }

}

Okay so I'm confused by all the stuff above. But I think you are still asking how to releaseOutside. To register an event to the stage you would do this:

stage.addEventListener(MouseEvent.MOUSE_UP,clipUp);

Don't add that and keep your existing code. You only need one. In other words you don't need a MOUSE_UP listener on both your clip and the stage -- you only need the one. So if your button or whatever it is is called clip you could have code something like this:

var curDrag:MovieClip;

clip.addEventListener(MouseEvent.MOUSE_DOWN,clipPress);

function clipPress(e:MouseEvent):void{

   stage.addEventListener(MouseEvent.MOUSE_UP,clipRelease);

   curDrag=e.target;

   curDrag.gotoAndStop(3);

   curDrag.startDrag();

}

function clipRelease(e:MouseEvent):void{

   stage.removeEventListener(MouseEvent.MOUSE_UP,clipRelease);

   curDrag.gotoAndStop(1);

   stopDrag();

}

I think that is what you are after.

Known Participant
June 11, 2009

any1 can help me solve my problem?

June 11, 2009

I'm going to guess it fires the MOUSE_OUT before it fires the MOUSE_UP.