• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

I cant use mouseup & mousedown

New Here ,
Feb 08, 2022 Feb 08, 2022

Copy link to clipboard

Copied

i watched a puzzle's game tutorial and i tried, he said to use mousedown&mouseup but it didnt work. then i searched on google saying to use pressup and it didnt work too.could you help me pleaseee...

 

var S1StartX: int = 30
var S1StartY: int = 30
var S1EndX: int = 507
var S1EndY: int = 30

 

S1.buttonMode = true;
S1.addEventListener(MouseEvent."pressdown", startDragging):
S1.addEventListener(MouseEvent."pressup", stopDragging):

 

var S2StartX: int = 185.45
var S2StartY: int = 563.1
var S2EndX: int = 661.05
var S2EndY: int = 30.5


S2.buttonMode = true;
S2.addEventListener(MouseEvent."pressdown", startDragging):
S2.addEventListener(MouseEvent."pressup", stopDragging):

var S3StartX: int = 7.2
var S3StartY: int = 311.4
var S3EndX: int = 786.25
var S3EndY: int = 30

 

S3.buttonMode = true;

S3.addEventListener(MouseEvent."pressdown", startDragging):
S3.addEventListener(MouseEvent."pressup", stopDragging):

 

var S4StartX: int = 133.75
var S4StartY: int = 120.8
var S4EndX: int = 507.
var S4EndY: int = 208

 

S4.buttonMode = true;

S4.addEventListener(MouseEvent."pressdown", startDragging):
S4.addEventListener(MouseEvent."pressup", stopDragging):

 

var S5StartX: int = 248.85
var S5StartY: int = 423.3
var S5EndX: int = 633.75
var S5EndY: int = 181.45

 

S5.buttonMode = true;

S5.addEventListener(MouseEvent."pressdown", startDragging):
S5.addEventListener(MouseEvent."pressup", stopDragging):

 

var S6StartX: int = 209.9
var S6StartY: int = 14.95
var S6EndX: int = 786.25
var S6EndY: int = 208

 

S6.buttonMode = true;
S6.addEventListener(MouseEvent."pressdown", startDragging):
S6.addEventListener(MouseEvent."pressup", stopDragging):

 

var S7StartX: int = 69.2
var S7StartY: int = 499
var S7EndX: int = 506.75
var S7EndY: int = 208

 

S7.buttonMode = true;
S7.addEventListener(MouseEvent."pressdown", startDragging):
S7.addEventListener(MouseEvent."pressup", stopDragging):

 

var S8StartX: int = 233.15
var S8StartY: int = 234.35
var S8EndX: int = 661.05
var S8EndY: int = 385.5

 

S8.buttonMode = true;
S8.addEventListener(MouseEvent."pressdown", startDragging):
S8.addEventListener(MouseEvent."pressup", stopDragging):

 

var S9StartX: int = 120.95
var S9StartY: int = 328.55
var S9EndX: int = 784.9
var S9EndY: int = 385.5

 

S9.buttonMode = true;
S9.addEventListener(MouseEvent."pressdown", startDragging):
S9.addEventListener(MouseEvent."pressup", stopDragging):

 

var S10StartX: int = 305.8
var S10StartY: int = 133.9
var S10EndX: int = 661.05
var S10EndY: int = 563.1

 

S10.buttonMode = true;
S10.addEventListener(MouseEvent."pressdown", startDragging):
S10.addEventListener(MouseEvent."pressup", stopDragging):

 

var S11StartX: int = 305.8

var S11StartY: int = 133.9
var S11EndX: int = 661.05
var S11EndY: int = 563.1

 

S11.buttonMode = true;
S11.addEventListener(MouseEvent."pressdown", startDragging):
S11.addEventListener(MouseEvent."pressup", stopDragging):

 

var S12StartX: int = 0.6
var S12StartY: int = 563
var S12EndX: int = 786.25
var S12EndY: int = 538.45

 

S12.buttonMode = true;
S12.addEventListener(MouseEvent."pressdown", startDragging):
S12.addEventListener(MouseEvent."pressup", stopDragging):

//-------------------------------------------------------------------

function startDragging(e:MouseEvent):void {
e.currentTarget.startDrag():
}

function stopDragging(e.MouseEvent):void {
e.currentTarget.stopDrag():
}

TOPICS
ActionScript , Code , Error , How to

Views

79

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 08, 2022 Feb 08, 2022

Copy link to clipboard

Copied

LATEST

Hi.

 

The way you're adding events is not correct.

 

Instead of

S2.addEventListener(MouseEvent."pressdown", startDragging):

 

It should be:

S2.addEventListener(MouseEvent.MOUSE_DOWN, startDragging):

 

It's also good practice to start instance names with lowercase letters and then capitalize the first letters of subsequent words in the name. This is called camel case. For example: s1, myPiece, startButton.

 

To create a drag and drop interactivity, what I like to do is to place all pieces in a single container and then add listeners to the container itself instead of adding to each piece. Like this:

 

AS3 code:

import flash.display.DisplayObjectContainer;
import flash.events.MouseEvent;

var i:int;
var total:int = pieces.numChildren;

function mouseDownHandler(e:MouseEvent):void
{
	e.target.startDrag();
	e.currentTarget.addChild(e.target); // send child to the top
}

function mouseUpHandler(e:MouseEvent):void
{
	e.target.stopDrag();
}

for (i = 0; i < total; i++)
	(pieces.getChildAt(i) as DisplayObjectContainer).mouseChildren = false;

pieces.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
pieces.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);

 

FLA / source / download:

https://bit.ly/3oweo52


Please let us know what else we can do for you.

 

Regards,

JC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines