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

probleme with drag and drop

New Here ,
May 18, 2014 May 18, 2014

hi I have a probleme with drag and drop I have 2 clip and i have 2 target, i want when i drag clip 1 to target 1 , the target 1 not accepte the clip2, so clip 2 can be draged to target 2 . (target 1 can accept clip 1 and clip 2, also target 2 can accepte clip 1 & 2)

// pierre

clip_piere.addEventListener(MouseEvent.MOUSE_DOWN, dep_piere);

clip_piere.addEventListener(MouseEvent.MOUSE_UP, arreter_piere);

clip_piere.buttonMode = true;

var x_piere,y_piere:Number;

x_piere=clip_piere.x;

y_piere=clip_piere.y;

function dep_piere(event:MouseEvent):void

{

  clip_piere.startDrag();

}

function arreter_piere(event:MouseEvent):void

{

  if(place1.hitTestObject(clip_piere) || place2.hitTestObject(clip_piere) ){

  clip_piere.stopDrag();

  clip_piere.removeEventListener(MouseEvent.MOUSE_DOWN, dep_piere);

  }else{

  clip_piere.x=x_piere;

  clip_piere.y=y_piere;

  clip_piere.stopDrag();

  }

}

// ean

clip_ean.addEventListener(MouseEvent.MOUSE_DOWN, dep_ean);

clip_ean.addEventListener(MouseEvent.MOUSE_UP, arreter_ean);

var x_ean,y_ean:Number;

x_ean=clip_ean.x;

y_ean=clip_ean.y;

function dep_ean(event:MouseEvent):void

{

  clip_ean.startDrag();

}

function arreter_ean(event:MouseEvent):void

{

  if(place1.hitTestObject(clip_ean) || place2.hitTestObject(clip_ean) ){

  clip_ean.stopDrag();

  clip_ean.removeEventListener(MouseEvent.MOUSE_DOWN, dep_ean);

  }else{

  clip_ean.x=x_ean;

  clip_ean.y=y_ean;

  clip_ean.stopDrag();

  }

}

TOPICS
ActionScript
525
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

LEGEND , May 18, 2014 May 18, 2014

Here is a link to a file I made for you that is based on your objects and what I described in my last response.  I have reduced the code so that the
objects share the same functions.  I moved the MOUSE_UP listener to the stage so that it is less prone to fail should you slide off the object when dragging and dropping.

http://www.nedwebs.com/Flash/AS3_Drag_Targets.fla

Translate
LEGEND ,
May 18, 2014 May 18, 2014

You should be using the dropTarget property of the dragged object to determine if it has been dropped on an object (you often have to target the parent of the dropTarget because it will be the child object inside the object you drop on).

Then what you can do is assign a status property to the targets to indficate whether or not they are used already. and use that in your logic to check if a target is open or not  That way, when you drop an object on one and it is valid, you designate the target as being used so that when you drop another you don't qallow it to stay.

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 ,
May 18, 2014 May 18, 2014

but how can i check if a target is open or not?  the code plz

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
LEGEND ,
May 18, 2014 May 18, 2014

I already explained that.  You assign a properrty to each target, call it "used" or "occupied" or something like that and set it to false initially.  When you try to drop something on the target you check to see if the used property is true or false.  If it is false you allow the drop and then set that property to be true.  That way the next object you drop on it will find the used property to be true and will not allow it to drop there.

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 ,
May 18, 2014 May 18, 2014

I understand you but witch property i have to assign "name" "text" ... and my target is textfield, plz help me  I am a beginner in as3.

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
LEGEND ,
May 18, 2014 May 18, 2014

Another way to approach this if you don't want to place the textfield in a movieclip is to have an array with the target textfields names.  When you drop onto one of them you lopp thru the array to check to see if it is in the array, and if it is you allow the drop and then remove that textfield from the array.  That way, if you try to drop another object on the same textfield it is no longer oin the array so your code doesn't allow the object to be dropped.

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
LEGEND ,
May 18, 2014 May 18, 2014

Here is a link to a file I made for you that is based on your objects and what I described in my last response.  I have reduced the code so that the
objects share the same functions.  I moved the MOUSE_UP listener to the stage so that it is less prone to fail should you slide off the object when dragging and dropping.

http://www.nedwebs.com/Flash/AS3_Drag_Targets.fla

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 ,
May 18, 2014 May 18, 2014

tks a lot but i m using flash CS5, can you save it as cs5 and thanks again

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
LEGEND ,
May 18, 2014 May 18, 2014

Try the same link again - I saved it as CS5 under the same name.

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 ,
May 18, 2014 May 18, 2014

thanks a lot that what i want, but its better if i can drag the "piere" or "ean" for the first time into place 2, not obligatory i will drag to place 1!!

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
LEGEND ,
May 18, 2014 May 18, 2014

For that change the arreter function to the following:

function arreter(event:MouseEvent):void
{
      draggedObject.stopDrag();
      stage.removeEventListener(MouseEvent.MOUSE_UP, arreter);

      if(places.indexOf(draggedObject.dropTarget) > -1){
            draggedObject.removeEventListener(MouseEvent.MOUSE_DOWN, dep);
            draggedObject.x = draggedObject.dropTarget.x;
            draggedObject.y = draggedObject.dropTarget.y;
            places.splice(places.indexOf(draggedObject.dropTarget),1);
      } else {
            draggedObject.x = draggedObject.XX;
            draggedObject.y = draggedObject.YY;
      }
}

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 ,
May 21, 2014 May 21, 2014
LATEST

thanks a lot that perfect

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