Solved

AS3 stage position of draggable object

Posted on 2011-09-28
10
748 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
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.

744 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

10 Experts available now in Live!

Get 1:1 Help Now