-
drag and drop success
How do I provide a success message (perhaps with a dynamic text field) when the three objects have been dragged to their targets?
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
public class Main2 extends Sprite
{
var xPos:int;
var yPos:int;
public function Main2():void
{
addListeners(ethic, discrim, account);
this.buttonMode = true;
this.useHandCursor = true;
}
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.na me + "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[i].addEventListener(MouseEvent.MOUSE_DOWN, dragObject);
objects[i].addEventListener(MouseEvent.MOUSE_UP, stopDragObject);
}
}
}
}
-
I just set up the exact same thing and the following PDF (and the others of the same topic and author - you'll find them) did it for me. Easy as pie.
http://www.flashclassroom.com/docs/d...sponsescs3.pdf
-
Thats pdf looks really good. I think Im going to have a lot of fun with that, and probably learn a fair amount too, which isn't always the case with online tutorials.
Thanks a bunch!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|