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
Solved

Snap to Movie Clips

Posted on 2003-11-04
4
329 Views
Last Modified: 2012-05-04
I have a movie that has 10 movie clip objects.  Each object has a different letter.  The objective here is that a student can click on a button, here a word and then try to spell the word by dragging the letters to boxes.  What I would like to happen is for the letters to snap to the center of the box once the letter is released on top of that box.

Right now once the release happens the letters just lay where they are dropped.

Example:

http://planetallison.com/ee/snapto/dls3.swf

0
Comment
Question by:skibama1
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:Calron
ID: 9684986
what you can do is add some positioning code when you stop the dragging:

somewhere in your code you have:

mc.stopDrag();

// calculate corrected position (snap to a grid)
mc._x = correctedX
mc._y = correctedY


Now to calculate the corrected position I'll give you a simple example that snaps to a 100x100 pixel grid

var correctedX = int(mc._x / 100) * 100;
var correctedY = int(mc._y / 100) * 100;

What this does is the following:  lets say my _x is 145.   145 / 100 = 1.45;  int(1.45) = 1; 1 * 100 = 100;
This of course can be refined a lot. In your case you will probably have to first check if the letter was released in the top part where you have the spaces to insert letters. If not, I would return the letter to its starting position at the bottom. The same for letters dropped somewhere outside of the top part.
In the top part define your grid where you want to  snap your letters to and do the calculations.
0
 
LVL 1

Author Comment

by:skibama1
ID: 9693093
OK, how do I go about changing the _X and _Y properties of the object?  I was assuming it would be:

setProperty("instance", _X, "xvalue");

but I nothing happens on the release
0
 
LVL 5

Accepted Solution

by:
Calron earned 125 total points
ID: 9693575
Give your movieclips an instancename. This name can be set in the properties window. then using that name you can access them like this:

myMC._x = 123;  // assuming you set myMC as instance name, give each movieclip a new name

depending on where you are trying to access the movieclip you micht have to write:

_root.myMC._x = 123;  // this is if you movieclip lies on the main timeline.


If you can't get this to work, post your fla and I'll write this straight into your fla.
0
 
LVL 1

Author Comment

by:skibama1
ID: 9696932
The _root solved the problem.  I also had to go back and set the _x & _y variables to calculate it based on the root.

That is:

var1 = _root.instance._x

instead of:

var1 = instance._x

Thanks for your help!!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Online Course Not Responding 3 96
File drag and drop 6 145
You Tube Videos not playing 9 128
flash professional 3 20
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…
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 shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
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.

791 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