Solved

AS3 stage position of draggable object

Posted on 2011-09-28
10
755 Views
Last Modified: 2013-11-11
I have an interaction that allows you to pick a projector, a lens, and more items for a particular theater based on some constraints.

I have the drag to the theater part working except I want the projector I dragged to be positioned just below the theater.

I have:
event.currentTarget.y = (stage.stageHeight - height) - 10;

Open in new window


but it's placing it relative to the theater instead of the stage.

Can someone explain how this works and how I can get the projector into the lower right quadrant?

[For some reason EE won't let me upload a CS5.5 version file... I had to downgrade it to CS4 in order to upload the file????]
 Theater.fla
0
Comment
Question by:pixystk
  • 5
  • 3
  • 2
10 Comments
 
LVL 10

Expert Comment

by:Carnou
ID: 36718556
I'm not at my workstation that has Flash, so can't experiment on your FLA, but I think I can talk you through this one.

If the event.currentTarget is being placed relative to the theater, that's because it's a child of the theater.  Positioning is always done in the local frame of reference.  If you want to position to stage coordinates, you need to convert from the global system to the system of the parent.

You should want something like this:
import flash.geom.Point;
var globalPoint:Point = new Point( event.currentTarget.x, stage.stageHeight - height - 10);
var localPoint:Point = event.currentTarget.parent.globalToLocal( globalPoint );
event.currentTarget.x = localPoint.x;
event.currentTarget.y = localPoint.y;

Sorry I can't test this on your fla, so I can't guarantee it, but it should get you working ok.
0
 
LVL 29

Expert Comment

by:dgofman
ID: 36718604
Where did you get such bad tutorial?
I changed your FLA
Theater.fla
0
 

Author Comment

by:pixystk
ID: 36718785
@dgofman - the projector is still remaining on the theater. I want it to shrink then move to the lower right corner of the stage (flash stage - not theater stage). And as I add addtional projectors how do I get them not to overlap?  I think I have to check to see if there are any have been dropped there first, right?

BTW --  the nasty coding is all ME trying to compile about 3 different tutorials into my own mess. :)

@carnou - I tried to implement your idea, but it broke.... no error, but can't drag my projector any longer.

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 29

Expert Comment

by:dgofman
ID: 36718831
@pixystk: Can you try to understand how my drop area working, just goto layer and move what ever you want...
0
 
LVL 29

Expert Comment

by:dgofman
ID: 36718843
... goto the second layer and dropArea symbol ...
0
 
LVL 10

Expert Comment

by:Carnou
ID: 36718856
I'm guessing you still have your regular drag operation working, just that the projector disappears once you stop dragging?  That means it's not liking the numbers it gets.  You could set a breakpoint (or use trace statements) and look to see what the x,y setting numbers are, and work some possibilities from there - that's the best way to learn!

Otherwise, if you or dgofman don't get it fixed before then, I'll grab your FLA late tonight and help you out further.
0
 

Author Comment

by:pixystk
ID: 36718975
Ok. I see that you've added a dropArea on the theater screen, but I need the little projector to move below the theater mc as the user is choosing a projector for that theater. They'll eventually choose a lens, a bulb, and a 3D system. So this would be similar to a shopping cart where the items selected would snap to a "cart area" but thumbnail sized.

Would it be better to create a specific cart area for that object and have it snap to those coords?
 screenshot of selected items placement
0
 
LVL 29

Accepted Solution

by:
dgofman earned 500 total points
ID: 36719019
Create a new Symbol like your red rectangle and when user dropped a projector set Y to

Symbol.y + 10; if you want to keep more than one projector in your "Cart area" you should remember your last X. example:

var lastCartX:uint = 0;

dropObject.x = lastCartX;

lastCartX += dropObject.width + 10;

dropObject.x = lastCartX;

lastCartX += dropObject.width + 10;

etc.

(10 - is 10 pixels gap)
0
 
LVL 29

Expert Comment

by:dgofman
ID: 36719033
Sorry set default value for  lastCartX

var lastCartX:uint = Symbol.x; (Symbol - red crome area)
 
0
 

Author Closing Comment

by:pixystk
ID: 36719194
I'm sure I'll have to post again soon. Hopefully I'll have worked out most of the mess before I post again!

Thanks again!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question