Solved

movie or graphic to vertically follow mouse tracking.

Posted on 2009-04-07
8
572 Views
Last Modified: 2013-11-11
I am trying to come up with a script that will follow only the movements of my mouse only vertically [.y?]

I have tried putting together a scrollable area with a mask and up and down buttons on a ROLL_OVER. But it is not exactly what I am after.

The perfect example of what i am trying to do is on the main landing page for FURLA.COM.

I am not asking for anyone to write a code for me.  I am just looking for help to be pointed in the right direction.

Any assistance is appreciated.
0
Comment
Question by:domestika
  • 5
  • 2
8 Comments
 

Author Comment

by:domestika
ID: 24093335
http://www.furla.com/

if this helps as a reference.

I am terribly new at AS3 and cannot even think of where to being, is this an enter.frame type of function of a mouse event?  I am pretty lost.

Thanks
0
 
LVL 19

Accepted Solution

by:
quizengine earned 500 total points
ID: 24111688
The attached example is pretty crude (e.g. there is no tweening of the shape as in your example) and I've just used vector shapes to keep the filesize down, but I think it may. Also some of the maths is pretty scrappy to get the scaling right, but maybe it will get you started.

To see the script, click the symbol on the stage and look in the actions panel. Basically the approach I took was to draw an imaginary line across the movie, half way down the y axis. If the mouse position was above that line, move the clip vertically (i.e. reduce the _y property) and if the mouse pointer were below that imaginary line to move the clip down the screen.

Hope it's of some use.
y-scroll-cs3.fla.jpg
0
 

Author Comment

by:domestika
ID: 24113007
Great!  thanks so much for that script.  It's so simple. I love it. What i did was to switch the direction of the clip so it moves opposite to the direction of the mouse movement.

My next question is:

How would I go about adding easing to the movie clip? And it there is a way to balance the amount that the clip moves top and bottom, I notice it tends to move more in one direction than the other.  No biggie. The easing it more important for me to get sorted.


y-scroll-cs3.fla.txt
0
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

 
LVL 19

Expert Comment

by:quizengine
ID: 24114281
I'm thinking it would be almost faster to write some easing code than to try and explain how i would go about it, but then I think you would learn less, so here goes.

You need to set a target _y position for the movieclip - a place where you want it to reach eventually. Then you need work out the difference (in pixels) between where the clip is now, and where it will be. Then you need to divide that by some scaling factor. For example, if you divided it by 10, it would take 10 frames to get there - I'll call this fractional distance the 'delta'. Then just add (or subtract) that *delta* value to the movieclips position each frame using the on (enterFrame) that's already on the clip.

Ok. So we now have fractional movement each frame, but not easing. This isn't  easing because the clip moves in standard increments each frame. With easing we need to have the clip move a different distance in each frame. In the example you showed, the clip moves a large distance quickly then as it approaches it's target place, it starts to move more slowly.

In order to do this we will need to reduce the delta each frame. So, if the variable were called delta_y, I would put something in there like

delta_y = delta_y *0.9;

which would reduce the amount the clip moves by 10% per frame. Now if you're good with maths, you'll realise that with this idea, the clip will *never* reach it's target - it will only ever get closer and closer. But from a practical point of view, the movement will get so small that it will appear to have come to rest.

Good luck experimenting.
0
 

Author Comment

by:domestika
ID: 24149108
so i have figured out what my 'delta_y' is and where the final position [final_y] of the image shall be.  

I have tried a couple of different ways of inserting that code into the (enterFrame) method, but I can't seem to produce results.  I thought by switching out a few values i could get results.

I am happy by the distance I am getting in the movement of the clip. by I am lost on how to create an equation to insert the delta value? [math's was not my strong point]

I feel as though I am totally missing something. But I am not too sure what?
onClipEvent (load) {
	mouse_ypos = _ymouse;
	start_y = 300; 		// middle of the stage
	y_offset = 300;		// half of stage height
	y_final = 275; 		// final position of image
	delta_y = 0.5; 		// fractional distance
}
 
onClipEvent (enterFrame) {
	this._y = start_y + ((y_offset + _ymouse)/(y_final - y_offset));
}

Open in new window

y-scroll-cs3.fla.txt
0
 

Author Comment

by:domestika
ID: 24326492
I have been super busy, that I haven't had a chance to work on this as yet.

But I now have a co-worker who only knows AS2.0.

I have never used AS2.0 before.  Will i have to rewrite this whole script [and more] to get it to work in 2.0?
0
 

Author Comment

by:domestika
ID: 24327462
Also, another thought in AS3.0

I have come up with this super easy script. BUT i need to find a way to stop the image at a certain point and to slow down it's movement. Then I just need to reverse the direction of the image to the opposite of whatever way the mouse moves...

Am I going about this the right way?
onClipEvent (enterFrame) {
_y += (_parent._ymouse-_y)*.1;
}

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java and adobe flash updates 4 52
You Tube Videos not playing 9 128
D3, SVG, dragging 3 144
Online photography 7 123
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…
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…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Learn the basics of inputting and editing your text components in Prezi. We will cover how to set styles, position, and group your text components. In your Prezi editor, click anywhere on the canvas to add text: A flashing cursor informs you that yo…

839 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