Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using flash & mousewheel - here's what I have! 1

Status
Not open for further replies.

whoknows361

Technical User
Sep 22, 2005
228
US
Hello, I am not a flash newb - but I am not a pro coder either. I have adopted an actionscript code for a custom scrollbar. the code is:
//begin scroll code//
stop();
scrolling = function () {
var scrollHeight:Number = scrollTrack._height;
var contentHeight:Number = contentMain._height;
var scrollFaceHeight:Number = scrollFace._height;
var maskHeight:Number = maskedView._height;
var initPosition:Number = scrollFace._y=scrollTrack._y;
var initContentPos:Number = contentMain._y;
var finalContentPos:Number = maskHeight-contentHeight+initContentPos;
var left:Number = scrollTrack._x;
var top:Number = scrollTrack._y;
var right:Number = scrollTrack._x;
var bottom:Number = scrollTrack._height-scrollFaceHeight+scrollTrack._y;
var dy:Number = 0;
var speed:Number = 10;
var moveVal:Number = (contentHeight-maskHeight)/(scrollHeight-scrollFaceHeight);

scrollFace.onPress = function() {
var currPos:Number = this._y;
startDrag(this, false, left, top, right, bottom);
this.onMouseMove = function() {
dy = Math.abs(initPosition-this._y);
contentMain._y = Math.round(dy*-1*moveVal+initContentPos);

};
};
scrollFace.onMouseUp = function() {
stopDrag();
delete this.onMouseMove;
};
btnUp.onPress = function() {
this.onEnterFrame = function() {
if (contentMain._y+speed<maskedView._y) {
if (scrollFace._y<=top) {
scrollFace._y = top;
} else {
scrollFace._y -= speed/moveVal;
}
contentMain._y += speed;
} else {
scrollFace._y = top;
contentMain._y = maskedView._y;
delete this.onEnterFrame;
}
};
};
btnUp.onDragOut = function() {
delete this.onEnterFrame;
};
btnUp.onMouseOut = function() {
delete this.onEnterFrame;
};
btnDown.onPress = function() {
this.onEnterFrame = function() {
if (contentMain._y-speed>finalContentPos) {
if (scrollFace._y>=bottom) {
scrollFace._y = bottom;
} else {
scrollFace._y += speed/moveVal;
}
contentMain._y -= speed;
} else {
scrollFace._y = bottom;
contentMain._y = finalContentPos;
delete this.onEnterFrame;
}
};
};
btnDown.onRelease = function() {
delete this.onEnterFrame;
};
btnDown.onDragOut = function() {
delete this.onEnterFrame;
};

if (contentHeight<maskHeight) {
scrollFace._visible = false;
btnUp.enabled = false;
btnDown.enabled = false;
} else {
scrollFace._visible = true;
btnUp.enabled = true;
btnDown.enabled = true;
}
};
scrolling();
//end scroll code//

Of course, each mc I load into the main is instance named contentMain. My basic set-up is that I have a main movie & then I load movies into a holder mc. these movies I load into holder mc have the scrollbar code. My question is, how do I make the movies that I load into the holder mousewheel scrollable?

here is what I think - I need to add a layer, but an invis button - remove the hand icon & put some actionscript for the mousewheel function. But I don't know how to do this. Please let me know how I can do this with the current actionscript I am using.

the site I am referring to is
I have created this site, but am unsure as how to use the mousewheel to scroll the loaded mc's, as opposed to a user having to click on the scrollbar & move down.
Thanks in advance, as this forum has been awesome for answers (ie. kenneth, newbie, etc.)

Jonathan
 
The most simplistic example would be something like this:
Code:
var lo:Object = new Object();
lo.onMouseWheel = function(delta:Number):Void  {
	contentMain._y += delta;
};
Mouse.addListener(lo);
stop();


Kenneth Kawamoto
 
where do I place this code? on the main movie? first frame.
 
thanks kenneth it worked, however. I need two more things:

how do I make the scroll move faster as it takes a while to move down or up.

And can I make the "scrollface" move down as you scroll the mousewheel down?

thanks bro

Jonathan
 
If it's too slow then you can do something like:
[tt]
contentMain._y += delta*2;
[/tt]
(Double speed)

To move the slider, you can just add:
[tt]
scrollFace._y += delta*2;
[/tt]

You'll also need to check if it's near the top or the bottom of the scrolling region. You have that in your existing code, you can just use the same tactics.


Kenneth Kawamoto
 
kenneth, thanks for the tip - but just a few more questions.

1) when I scroll the page down - the scrolltrack goes up & vice versa (the wrong way). how do I fix this?

2) You wrote, "You'll also need to check if it's near the top or the bottom of the scrolling region. You have that in your existing code, you can just use the same tactics."

Unfortunately, though I have adopted this code - I do not understand all of it at my current skill level. Can you be a bit more specific? Thanks so much

Jonathan
 
> 1) when I scroll the page down - the scrolltrack goes up & vice versa (the wrong way). how do I fix this?

Just reverse the operator:
[tt]
scrollFace._y -= delta*2;
[/tt]

> 2) You wrote, "You'll also need to check if it's near the top or the bottom of the scrolling region. You have that in your existing code, you can just use the same tactics."

The piece of your code I was referring was things like this one:
[tt]
if (contentMain._y + speed < maskedView._y) { ... }
[/tt]

You should employ the same thing for the mouse wheel, otherwise your content can go up (or down) forever into the nomans land. It would be something like (NB. this is a guess):
Code:
lo.onMouseWheel = function(delta:Number):Void  {
	if (delta>0) {
		if (contentMain._y+delta*2>finalContentPos) {
			contentMain._y = finalContentPos;
		} else {
			contentMain._y += delta*2;
			scrollFace._y -= delta*2;
		}
	} else {
		if (contentMain._y+delta*2<maskedView._y) {
			contentMain._y = maskedView._y;
		} else {
			contentMain._y += delta*2;
			scrollFace._y -= delta*2;
		}
	}
};

Kenneth Kawamoto
 
I was able to make it work right according to your examples. Thanks so much Kenneth as I have learned throughout this question.

Jonathan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top