Solved

AS3 stage position of draggable object

Posted on 2011-09-28
10
751 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
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…
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.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

810 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