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

Drag and drop dress up

New Here ,
Jul 05, 2017 Jul 05, 2017

hi everyone. some years ago, I made a dress up game with AS2. And it worked perfectly ! Now i would like make an other one. but the current version of flash are only with AS3.

OK. I tried. But nothing go like i would like !

here is my as3 script :

rap1.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);

rap1.addEventListener(MouseEvent.MOUSE_UP, dropMe);

rap2.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);

rap2.addEventListener(MouseEvent.MOUSE_UP, dropMe);

rap3.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);

rap3.addEventListener(MouseEvent.MOUSE_UP, dropMe);

rap4.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);

rap4.addEventListener(MouseEvent.MOUSE_UP, dropMe);

rap5.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);

rap5.addEventListener(MouseEvent.MOUSE_UP, dropMe);

rap6.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);

rap6.addEventListener(MouseEvent.MOUSE_UP, dropMe);

rap7.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);

rap7.addEventListener(MouseEvent.MOUSE_UP, dropMe);

function pickMe(event:MouseEvent):void {

    event.target.startDrag(true);

}

function dropMe(event:MouseEvent):void {

    event.target.stopDrag();

}

All go wrong with me, it is the same for you ?

I send you my SWF :

fastSWF - Free Flash and Unity Hosting

What should i do ?

THX

TOPICS
ActionScript
1.4K
Translate
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

correct answers 1 Correct answer

Enthusiast , Jul 05, 2017 Jul 05, 2017

//Store the items in array:

var dressArray:Array = [rap1, rap2, rap3, rap4, rap5, rap6, rap7];

//Add mouse event listener for all of them using for() loop:

var i:uint;

for (i = 0; i< dressArray.length; i++)

{

     dressArray.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);

     dressArray.addEventListener(MouseEvent.MOUSE_UP, dropMe);

};

//Start & stop drag functions:

function pickMe(e:MouseEvent):void

{

     e.currentTarget.startDrag();

};

function dropMe(e:MouseEvent):void

{

     e.currentTarget.stopDrag();

}

Translate
LEGEND ,
Jul 05, 2017 Jul 05, 2017

You have a registration point problem. If you mouse down on any object, that object immediately jumps to the right and down of the cursor position. So, each of your objects has its registration point set at the upper left corner of the movieClip. Move each reg point to some area near the center where there is an actual part of the object to be moved. Then the mouse up will work.

Translate
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
Enthusiast ,
Jul 05, 2017 Jul 05, 2017

First, I would change your pickMe function to startDrag(false) so you don't use lockCenter.

Then I would remove all the listeners you add that call dropMe - all you need is a single one:

stage.addEventListener(MouseEvent.MOUSE_UP, dropMe);

and then in dropMe call stopDrag() with no parameter, it doesn't need one.

Final code like so:

rap1.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);

rap2.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);

rap3.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);

rap4.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);

rap5.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);

rap6.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);

rap7.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);

stage.addEventListener(MouseEvent.MOUSE_UP, dropMe);

function pickMe(e:MouseEvent):void

{

    e.target.startDrag(false);

}

function dropMe(e:MouseEvent):void {

    stopDrag();

}

Translate
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
Enthusiast ,
Jul 05, 2017 Jul 05, 2017

//Store the items in array:

var dressArray:Array = [rap1, rap2, rap3, rap4, rap5, rap6, rap7];

//Add mouse event listener for all of them using for() loop:

var i:uint;

for (i = 0; i< dressArray.length; i++)

{

     dressArray.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);

     dressArray.addEventListener(MouseEvent.MOUSE_UP, dropMe);

};

//Start & stop drag functions:

function pickMe(e:MouseEvent):void

{

     e.currentTarget.startDrag();

};

function dropMe(e:MouseEvent):void

{

     e.currentTarget.stopDrag();

}

Translate
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
New Here ,
Jul 05, 2017 Jul 05, 2017

Woaw ! so many different answer for one problem !

(but i didn't really got that )

var i:uint;

for (i = 0; i< dressArray.length; i++)

thx you so much guys ! that has solve the half of my problem ^u^

my second question :

in my old as2 game, when the mouse was on the clothes, the cursor turned into a hand : whereever was the cursor, if it was on one part of the cloth, i could drag.

But for my current game, the cursor remain an arrow (like if i there was nohing to interact with), the dragging clothes isn't logical :

i can move a cloth by the transparent part of layers and and i can't move some of them before moving the other ones.

I let you see : i can't move the pant before the t-shirt

fastSWF - Free Flash and Unity Hosting

What have i to do to do ?

Translate
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
Enthusiast ,
Jul 05, 2017 Jul 05, 2017

Add this line to the code:

for (i = 0; i< dressArray.length; i++)

{

     dressArray.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);

     dressArray.addEventListener(MouseEvent.MOUSE_UP, dropMe);

     dressArray.buttonMode = true;

};

Translate
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
New Here ,
Jul 05, 2017 Jul 05, 2017

thank you so much nezarov !

just a last question : why your script worked better than the other ?

Translate
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
Enthusiast ,
Jul 05, 2017 Jul 05, 2017

You're welcome.

The answer for the second part of your question "i can move a cloth by the transparent part of layers and and i can't move some of them before moving the other ones.":

You can't ignore the transparent area of the bitmap through startDrag() method. The active area is the bounds (rectangle) of the bitmap , you can change the rectangle square only:

e.currentTarget.startDrag(false, bounds(rectangle));

Translate
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
New Here ,
Jul 05, 2017 Jul 05, 2017
LATEST

The problem is that i couldn't use the script for with bitmap. cause of the occurence name, i couldn't give a occurence name to a bitmap, so i turned them all into movie clip to use the script. does that mean that i can remove the transparent now they are movieclip ?

Translate
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
Enthusiast ,
Jul 05, 2017 Jul 05, 2017

Regarding the for() loop which you didn't get it, take a look here to know how it works:

Adobe ActionScript 3.0 * Looping

Translate
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