Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

AS3 stage position of draggable object

Posted on 2011-09-28
10
Medium Priority
?
760 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The goal of the tutorial is to teach the user how to how to record live broadcast.
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.
Suggested Courses

609 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