Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 10-07-2011, 03:23 PM   #1
rhanna2
Member
 
Join Date: Nov 2007
Posts: 70
Default Drag and Drop Issue

Hi,
I have the following script and I'm having a problem that the movie clips are draggable but they do not drop. It's probably something very simple, can someone help me, please!!!!

Thanks

ActionScript Code:
import flash.display.MovieClip; // you need to create the variables var xstart:Number = 0; var ystart:Number = 0; var mcAnswer:MovieClip; a1_mc.addEventListener(MouseEvent.MOUSE_DOWN,onePress); a2_mc.addEventListener(MouseEvent.MOUSE_DOWN,onePress); a3_mc.addEventListener(MouseEvent.MOUSE_DOWN,onePress); a4_mc.addEventListener(MouseEvent.MOUSE_DOWN,onePress); a5_mc.addEventListener(MouseEvent.MOUSE_DOWN,onePress); a6_mc.addEventListener(MouseEvent.MOUSE_DOWN,onePress); a7_mc.addEventListener(MouseEvent.MOUSE_DOWN,onePress); a8_mc.addEventListener(MouseEvent.MOUSE_DOWN,onePress); a9_mc.addEventListener(MouseEvent.MOUSE_DOWN,onePress); a10_mc.addEventListener(MouseEvent.MOUSE_DOWN,onePress); a11_mc.addEventListener(MouseEvent.MOUSE_DOWN,onePress); a12_mc.addEventListener(MouseEvent.MOUSE_DOWN,onePress); a13_mc.addEventListener(MouseEvent.MOUSE_DOWN,onePress); a14_mc.addEventListener(MouseEvent.MOUSE_DOWN,onePress); a15_mc.addEventListener(MouseEvent.MOUSE_DOWN,onePress); a16_mc.addEventListener(MouseEvent.MOUSE_DOWN,onePress); function onePress(evt:MouseEvent):void{     /*     evt.currentTarget refers to the object     on the EventListeners which has trigger     the event.     so for example if answer2_mc was pressed.     then the press is the event being triggered     and answer2_mc is what currentTarget     would be refering to.     */     evt.currentTarget.startDrag(true);     setChildIndex(evt.currentTarget,numChildren-1);     textField.text="";     xstart = evt.currentTarget.x;     ystart = evt.currentTarget.y; } a1_mc.addEventListener(MouseEvent.MOUSE_UP,oneRelease); a2_mc.addEventListener(MouseEvent.MOUSE_UP,oneRelease); a3_mc.addEventListener(MouseEvent.MOUSE_UP,oneRelease); a4_mc.addEventListener(MouseEvent.MOUSE_UP,oneRelease); a5_mc.addEventListener(MouseEvent.MOUSE_UP,oneRelease); a6_mc.addEventListener(MouseEvent.MOUSE_UP,oneRelease); a7_mc.addEventListener(MouseEvent.MOUSE_UP,oneRelease); a8_mc.addEventListener(MouseEvent.MOUSE_UP,oneRelease); a9_mc.addEventListener(MouseEvent.MOUSE_UP,oneRelease); a10_mc.addEventListener(MouseEvent.MOUSE_UP,oneRelease); a11_mc.addEventListener(MouseEvent.MOUSE_UP,oneRelease); a12_mc.addEventListener(MouseEvent.MOUSE_UP,oneRelease); a13_mc.addEventListener(MouseEvent.MOUSE_UP,oneRelease); a14_mc.addEventListener(MouseEvent.MOUSE_UP,oneRelease); a15_mc.addEventListener(MouseEvent.MOUSE_UP,oneRelease); a16_mc.addEventListener(MouseEvent.MOUSE_UP,oneRelease); function oneRelease(evt:MouseEvent):void{     evt.currentTarget.stopDrag();     switch(evt.currentTarget){         case a1_mc:         mcAnswer=benefit2011001_mc;         break         case a2_mc:         mcAnswer=benefit2011001_mc;         break         case a3_mc:         mcAnswer=benefit2011001_mc;         break         case a4_mc:         mcAnswer=benefit2011001_mc;         break         case a5_mc:         mcAnswer=benefit2011002_mc;         break         case a6_mc:         mcAnswer=benefit2011002_mc;         break         case a7_mc:         mcAnswer=benefit2011002_mc;         break         case a8_mc:         mcAnswer=benefit2011002_mc;         break         case a9_mc:         mcAnswer=benefit2011003_mc;         break         case a10_mc:         mcAnswer=benefit2011003_mc;         break         case a11_mc:         mcAnswer=benefit2011003_mc;         break         case a12_mc:         mcAnswer=benefit2011003_mc;         break         case a13_mc:         mcAnswer=allPlans_mc;         break         case a14_mc:         mcAnswer=allPlans_mc;         break         case a15_mc:         mcAnswer=allPlans_mc;         break         case a16_mc:         mcAnswer=allPlans_mc;         break     }         if (evt.currentTarget.hitTestObject(mcAnswer)) {         textField.text="Correct!";         /*         numbers aren't strings so we convert it         to a string so we can use it for the textfield         */         evt.currentTarget.enabled = false;     }     else {         textField.text="Incorrect.";         evt.currentTarget.x = xstart;         evt.currentTarget.y = ystart;     } }
rhanna2 is offline   Reply With Quote
Old 10-07-2011, 06:02 PM   #2
solisarg
Senior Member
 
solisarg's Avatar
 
Join Date: Mar 2003
Location: Buenos Aires, Argentina
Posts: 496
Default

I had recently the same problem. In my case, I use something like this:

this.stage.addEventListener(MouseEvent.MOUSE_UP,on eRelease);

Also since Flash allows to only drag one element, you can use just stopDrag() whitout explicitly reference to the element beeing dragged. In fact, in the event.target you still receive the reference to the MC beeing dragged, so you don't need 16 listeners to the MOUSE_UP, but just one

Jorge
solisarg is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:29 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.