Hi!
I've written a class to scroll up a clip based on mouse position..
maybe someone will find it helpfull..
I'm not a math genius so maybe you can have the same result with less code...
u can find files here:
http://www.thetconcept.com/flepstudio/Sposta_Mouse.zip
(for now they're not in english I'll translate them as soon as I can.. anyway here you can find a quick translation of what are doing the main methods)
on my TimeLine I've got a Clip called clip_mc of 929 px width..
the class I've written:
Code:
package
{
import flash.display.MovieClip;
import flash.events.*;
//sposta mouse= move mouse
public class Sposta_Mouse extends MovieClip
{
private var xmouse:Number=0;
private var xClip:Number=0;
private var speed:Number;
private var widthmovie:Number=550;
private var windthClip:Number=929;
private var scrollspeed :Number=10;
private var velocita:Number;
public function Sposta_Mouse()
{
init();
}
private function init():void
{
stage.frameRate=31;
initListeners();
}
private function initListeners():void
{
clip_mc.addEventListener(Event.ENTER_FRAME, sposta);
}
//move
private function sposta(event:Event):void
{
xmouse = mouseX - (widthmovie / 2);
// Setto la speed:
speed = (xmouse) / scrollspeed;
// se la speed è negativa la rendo positiva..
if (speed < 0) {
speed = -(speed);
}
areaSensibile();
rallentoScrollEccessivo();
scrollOpposti();
stopScroll();
// let's move the clip!
clip_mc.x=xClip;
}
//sensible area
private function areaSensibile():void
{
//se il mouse non è tra questi due punti non sposto
if (mouseY > 246) {
speed=0;
}
if (mouseY < 90) {
speed=0;
}
}
//here I decrease the excess of scroll witch wasn't cool
private function rallentoScrollEccessivo():void
{
if (speed > (xClip*2)) {
speed = speed/3;
}
}
//here the scroll is inverted..
private function scrollOpposti():void
{
//if mouse goes left scroll goes right isn't it?
if (xmouse < 0) {
xClip = xClip + speed;
}
// e viceversa aka che te lo dico affà
if (xmouse > 0) {
xClip = xClip - speed;
}
}
private function stopScroll():void
{
// here I'm checking the left end of the Clip
if (xClip > 0) {
xClip = 0;
}
// here the right end
if (xClip < -(windthClip - widthmovie)) {
xClip = -(windthClip - widthmovie);
}
}
}
}
few words 'bout:
Code:
//here I decrease the excess of scroll witch wasn't cool
private function rallentoScrollEccessivo():void
{
if (speed > (xClip*2)) {
speed = speed/3;
}
}
maybe it hasn't much sense but without it if I go from an are wich is not active to an extremity of the movie(active) the scroll is excessive..
if you find something better please let me know..
See Ya! :)
(ps. any blast or advice to improve it is welcome!!)