I’ll try to ask the question once more, since I did’nt explain the problem or show the whole code the last time.
Im creating a sort of knowledge game at a schoolproject, but have a problem now that I just could’nt solve by just reading.
I have 10 objects on the stage, 5 of those should be draggable objects and have a target object to be dragged to named the same as the object, only adding “target_” first. So “objectA” should be dragged and dropped at “target_objectA”. And the target objects have a rollover function inside that simply highlights the objects on rollover.
But since the rollover functions does’nt work when the mouse is dragging something, I had to set the “mouseEnabled” to false. But then again, flash will not recognize my mouse_up to run the “dropObject” function I’ve created, which drops the object at the position the mouse is at that time.
I just cant figure out what to do, and I need to keep the functions so that all dragobjects can run them, because later on I’m going to add alot more.
How can I get the rollover, startdrag and stopdrag to work all together, and if so: how?
//Imports and Stops
import caurina.transitions.*;
stop();
//Variables
var startX:Number;
var startY:Number;
var counterUp:Number = 0;
var counterDown:Number = 5;
//EventListeners
objectA.addEventListener(MouseEvent.MOUSE_DOWN, dragObject);
objectA.addEventListener(MouseEvent.MOUSE_UP, dropObject);
objectA.buttonMode = true;
objectB.addEventListener(MouseEvent.MOUSE_DOWN, dragObject);
objectB.addEventListener(MouseEvent.MOUSE_UP, dropObject);
objectB.buttonMode = true;
objectC.addEventListener(MouseEvent.MOUSE_DOWN, dragObject);
objectC.addEventListener(MouseEvent.MOUSE_UP, dropObject);
objectC..buttonMode = true;
objectD.addEventListener(MouseEvent.MOUSE_DOWN, dragObject);
objectD.addEventListener(MouseEvent.MOUSE_UP, dropObject);
objectD.buttonMode = true;
objectE.addEventListener(MouseEvent.MOUSE_DOWN, dragObject);
objectE.addEventListener(MouseEvent.MOUSE_UP, dropObject);
objectE.buttonMode = true;
//Functions
function dragObject(event:MouseEvent):void
{
event.target.startDrag(true);
event.target.mouseEnabled = false;
message_txt.text = "";
startX = event.target.x;
startY = event.target.y;
}
function dropObject(event:MouseEvent):void
{
event.target.stopDrag();
var myTargetName:String = "target_" + event.target.name;
var myTarget:DisplayObject = getChildByName(myTargetName);
if (event.target.dropTarget != null && event.target.dropTarget.parent == myTarget)
{
message_txt.text = "Good, only " + counterDown + " object left to go!";
event.target.removeEventListener(MouseEvent.MOUSE_DOWN, dragObject);
event.target.removeEventListener(MouseEvent.MOUSE_UP, dropObject);
event.target.buttonMode = false;
event.target.parent.removeChild(event.target);
event.target.x = myTarget.x;
event.target.y = myTarget.y;
counterUp++;
counterDown--;
}
else
{
message_txt.text = "Try again! You have " + counterDown + " objects left!";
Tweener.addTween(event.target,
{x:startX, y:startY, time:1, transition:"easeIn"});
}
if(counterUp == 5)
{
gotoAndPlay(2)
}
}