Solved

AS3 stage position of draggable object

Posted on 2011-09-28
10
749 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
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 select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now