PDA

View Full Version : [AS3] simple drag and drop game


spes
09-15-2008, 11:29 AM
Hey, I'm no programmer and not so good in actionscript (in AS3). I can't seem to find anything out there that could help me with what I'm trying to do. Which is a simple "drag and drop on to a target" kind of game where there are several draggable objects and drop targets on screen. So here's what I need help with:

1) the ability to drag any objects and can be dropped on any drop targets.

2) the ability to drag any objects and can only be dropped on certain drop targets.

3) the ability to drag any objects of the same kind, and drop it on certain drop targets.

4) if the correct kind of object is dropped on the correct drop target, an action will execute (immediately or at a later time).


The only solution I can imagine is by labeling certain objects into classes (ie: small object, big object etc.) and telling the target to allow these certain classes to be dropped on them. But I have absolutely no idea how to even start that.

Can anyone direct me on how to do this? A link or keywords I should be searching for online? Thank you in advance. ;)

spes
09-16-2008, 04:22 AM
Anyone? :confused:

I did run into something similar to what I'm looking for by determining the type of object by its name but it was for specific items for specific drop target.. the example they gave is by naming the objects box01, box02 etc.. and drop targets named smallBoxbox01, smallBoxbox02, etc. So it only allows specific objects to drop onto a specific drop target:

"smallBox" + event.target

event.target being the name of my object that is currently dragged. But that would only mean I can drop box01 onto smallBoxbox01.


So i am looking for a way to tell the drop target to check, for example, "smallBox" in the name of the objects as a type (smallBox_1, smallbox_2).. So that when an object with the name "smallBox" in it, it will allow that object to be dropped on that target?

Thanks again..

pradvan
09-22-2008, 03:43 PM
I wrote an inventory code with drag drop & snap that should be able to help you, or atleast push you in the right direction.

Basically you create an array of slots (where you drop items)
Give each slot a type
Create items (things you drag)
Set which slots the items can go in to.

Sample fla here:
Drag drop & snap inventory system (http://www.freeactionscript.com/2008/11/drag-drop-snap-inventory-system-v2/)

cheah
09-23-2008, 07:53 PM
Check out Monkeyflash.com
They have a nice tutorial about how to design the drag/drop

http://www.monkeyflash.com/flash/drag-and-drop-in-as3/

If that doesn't help you just google "drag and drop AS3" and you will be able to pull up an unlimited amount of information there. you should find something you're looking for.

cosmicshining
02-19-2010, 06:48 PM
i try to do a similar thing and found pradvan's tutorial very useful

check it

rodrigortiz
05-11-2010, 03:09 PM
Hi there, i`ve done an example for it, check it on
http://blog.rodrigortiz.com/?p=68

hope you like it.

pradvan
11-04-2010, 03:38 PM
Wrote an AS3 version of my old as2 inventory system. It follows OOP concepts and should be easy to understand and extend.

Example and source code available here:
http://www.freeactionscript.com/2010/11/drag-drop-and-snap-inventory-system/