Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-01-2010, 04:57 PM   #1
sakib15
Registered User
 
Join Date: Mar 2010
Posts: 16
Default Advanced Drag & Drop - Recognizing Other Container Objects

Hey folks. Scenario is as follows:

Situation: I'm making an inventory system for a RPG for my employer (small game developing company). There is a flash asset of an inventory page, with about 4 layers, 1 layer containing 7 children of the inventory, 3 other layers for shapes and what not... the entire project is in Flex Builder 3.0 now, and I'm embedding all the flash assets as a .swc file so I can create the object. I've added a VBox, and inside it I have 3 HBoxes, inside them I have lots of slots (Boxes) acting as holders for items. The items are added into the boxes. The items are UIComponent objects.

Problem: How can I access other boxes while I am dragging an item around? I've tried using the dropTarget property but it doesn't give me the parent of the item...which should be the box(acting as a slot or container), it gives me some other random art...and dropTarget property is read only. This means that I hold down the mouse button on top of an item, keep holding it an moving around, but when I move it around, I want other boxes to recognize that the item is over them. Note that these boxes are unique...there are 48 of them as mentioned, and they are all at the same level of depth.

Goal: Whenever I drag an item and drop it. I want it to snap into the middle of a box, based on positions. First and foremost, I need access to other box objects (parent of the item object) to make any circumstances for dropping.

Any help is appreciated. Thank you.

- Sakib I.
sakib15 is offline   Reply With Quote
Old 04-01-2010, 05:26 PM   #2
sparX
!Senior Member
 
Join Date: Jan 2010
Posts: 1,675
Default

Am i missing something or have u tried simply the dropTarget.parent property?
sparX is offline   Reply With Quote
Old 04-01-2010, 06:25 PM   #3
sakib15
Registered User
 
Join Date: Mar 2010
Posts: 16
Default

@ SparX,

Thank you for your reply.

Thing is that when I drop the item, I trace out the drop target and its some instance58 shape or something...which is a component of the tv screen or something (much higher in display list). I want to somehow designate the slots as the drop targets of the items but the property is read only.
sakib15 is offline   Reply With Quote
Old 04-01-2010, 06:44 PM   #4
abeall
Senior Member
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,812
Send a message via AIM to abeall
Default

Yeah, honestly I've always had trouble trying to get dropTarget to work in anything but very simple situations, you're probably better off doing the drop targeting yourself with your own analyzation routines in a mouseMove event. There may be some way to get more control over it but I've never found a way. Also I'm not familiar enough to know whether or not Flex has some built in drag and drop system, I thought it did.

Now in your case it sounds like your drop targets are a neat grid of boxes, which should make the drop targeting pretty easy from a mathematical perspective. So basically you would track mouseMove and first check to see if the mouse is inside the bounds of the inventory bar. If it is, you can find the box it's over pretty easily if you know the number of rows and columns using a little math and rounding. Hopefully that gives you some ideas.
__________________
Aaron Beall | Flash portfolio | Fireworks extensions | Twitter

Last edited by abeall; 04-01-2010 at 06:51 PM.
abeall is offline   Reply With Quote
Old 04-01-2010, 06:50 PM   #5
sparX
!Senior Member
 
Join Date: Jan 2010
Posts: 1,675
Default

U could maybe do something like iterate thru the main containers & use the contains() method of DisplayObjectContainer to see if the dropTarget is a child of the container & then find the intended drop zone from there perhaps..

Hard to say without seeing the makeup of these objects or how complex their display lists are..

edit: or better would prob be what abeall said...
sparX is offline   Reply With Quote
Old 04-01-2010, 07:06 PM   #6
krayzeebean
Senior Member
 
Join Date: Feb 2006
Posts: 682
Default

have you tried using getObjectsUnderPoint? You can use the mouse location as the point and see which of your drop targets are in the array. http://help.adobe.com/en_US/AS3LCR/F...ctsUnderPoint()
krayzeebean is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:55 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.