You must be logged in to post Login Register
Search 

drag and drop

User Post

11:55 am
October 28, 2010


sosodef

New Member

posts 1

1

Hi all,

I need some help – i'm new to flash AS3. I am trying to create an drag drop activity where the user can match words and meanings by dropping and dragging into the right space.

At the moment I want to create multiple drop areas for the boxes. At the moment they will only fall within their own target area – also only the boxes move and not the text. How do i create mutiple
drop areas for the words and meanings?

Here's my code

var objectoriginalX:Number;
var objectoriginalY:Number;

metal_mc.buttonMode = true;
metal_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
metal_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);

nonmetal_mc.buttonMode = true;
nonmetal_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
nonmetal_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);

metalloid_mc.buttonMode = true;
metalloid_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
metalloid_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);

function pickupObject(event:MouseEvent):void {
event.target.startDrag(true);
event.target.parent.addChild(event.target);
objectoriginalX = event.target.x;
objectoriginalY = event.target.y;
}
function dropObject(event:MouseEvent):void {
event.target.stopDrag();
var matchingTargetName:String = “target” + event.target.name;
var matchingTarget:DisplayObject = getChildByName(matchingTargetName);
if (event.target.dropTarget != null && event.target.dropTarget.parent == matchingTarget){
event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
event.target.removeEventListener(MouseEvent.MOUSE_UP, dropObject);
event.target.buttonMode = false;
event.target.x = matchingTarget.x;
event.target.y = matchingTarget.y;
} else {
event.target.x = objectoriginalX;
event.target.y = objectoriginalY;
}
}

http://megaswf.com/serve/64618/


Thanks so much. Even if you a place where i can find that kind of tutorial would be much appreciated.

sosodef

Topic RSS 
Search