Going to another frame after all items are in place
Hello All!
I'm making some simple drag'n'drop games and am using this code to make it work:
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
public class Main extends Sprite
{
var xPos:int;
var yPos:int;
public function Main():void
{
addListeners(s1, s2, s3, i1, i2, i3, n1, n2, n3, p1, p2, p3, b1, b2, b3, f1, f2, f3);
}
private function getPosition(target:Object):void
{
xPos = target.x;
yPos = target.y;
}
private function dragObject(e:MouseEvent):void
{
getPosition(e.target);
e.target.startDrag(true);
}
private function stopDragObject(e:MouseEvent):void
{
if (e.target.hitTestObject(getChildByName(e.target.name + "Target")))
{
e.target.x = getChildByName(e.target.name + "Target").x;
e.target.y = getChildByName(e.target.name + "Target").y;
}
else
{
e.target.x = xPos;
e.target.y = yPos;
}
e.target.stopDrag();
}
private function addListeners(... objects):void
{
for (var i:int = 0; i < objects.length; i++)
{
objects.addEventListener(MouseEvent.MOUSE_DOWN, dragObject);
objects.addEventListener(MouseEvent.MOUSE_UP, stopDragObject);
}
}
}
}
s1, s2, s3, i1, i2, i3, n1, n2, n3, p1, p2, p3, b1, b2, b3, f1, f2, f3 are objects that need to be placed correctly to win. So when they are placed correctly, what do I do to make the game recognize that the player did everything right? I'd like the game to be able to take it to another frame where a "win" graphic can be seen.
Any suggestions?
