ladybug
ladybug

Reputation: 21

Drag & Drop - ActionScript3

I am developing a simple flash game - a drag and drop game for children.

I have created three animal instances which will be dragged and dropped to the correct space. I am just adding action script and am getting the following error when trying to add drag and drop functions;

Scene 1, Layer 'Actions', Frame 1, Line 10, Column 44 1119: Access of possibly undefined property startDragging through a reference with static type String.Scene 1, Layer 'Actions', Frame 1, Line 10, Column 44 1136: Incorrect number of arguments. Expected 2.

My code is as follows; import flash.events.MouseEvent;

stop();

//set up the buttons for the puzzle pieces

Pig.buttonMode=true;

Pig.addEventListener(MouseEvent.MOUSE_DOWN.startDragging);
Pig.addEventListener(MouseEvent.MOUSE_UP.stopDragging);

function startDragging(e:MouseEvent){


trace("startDragging");

}

function stopDragging(e:MouseEvent){

trace("stopDragging");

}

Upvotes: 0

Views: 61

Answers (1)

www0z0k
www0z0k

Reputation: 4434

Should be

Pig.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
Pig.addEventListener(MouseEvent.MOUSE_UP, stopDragging);

MouseEvent.MOUSE_UP is a String and it doesn't have a property called startDragging. To add a listener you should pass a function reference as a second argument of addEventListener (using comma, no a dot)

Upvotes: 1

Related Questions