Method 2: Javascript
This is the old way to allow for the use of the mouse wheel in flash. Its main advantage over the flash player 7 method is the fact that it can be used within movie exported with older flash versions. The disadvantage is the it requires javascript..
Note: Click you must on the movie to set focus.
Download Source Files
The code used was created by one of the web gurus on MustardLab.com
<script type="text/javascript">
function enableScroll(obj){
obj.canScroll = true;
}
function disableScroll(obj){
obj.canScroll = false;
}
function scrollFlash(obj){
if(obj.canScroll == true){
window.event.returnValue = false;
if (window.event.wheelDelta >= 120){
var scrollSpeed = -3;
}else if(window.event.wheelDelta <= -120){
var scrollSpeed = 3;
}
obj.SetVariable("_root.scrollWheel ",scrollSpeed);
}
}
</script>The code used to embed the flash in html will need to be changed.
<object id="Mouser" data="mousewheel.swf" width="480" height="300" onmousewheel="scrollFlash(this)" type="application/x-shockwave-flash"> <param name="movie" value="mousewheel.swf" /> </object>
Now for the Actionscript
_root.onEnterFrame = function() {
if (scrollWheel != 0) {
_root.myTextField.scroll += parseInt(scrollWheel);
scrollWheel = 0;
}
mousewheeltext.onSetFocus = function() {
if(this.maxscroll > 1){
getUrl("javascript:enableScroll(document.flashObjectId)");
}
};
mousewheeltext.onKillFocus = function(){
getUrl("javascript:disableScroll(document.flashObjectId)");
}
To set up the flash movie all you need to do is create a textfield and give it the instancename 'mousewheeltext'. Once you publish the movie the textfield needs to be clicked on to SetFocus. When the focus is set the text can then be scrolled using the mousewheel.
The mousewheel value is taken from javascript and then passed onto flash the depending on wether the focus is set flash sends variables back to javascript enabling or disabling the scrollflash function.