Cyberspace Nova

MouseControl class - easy adding of mouse scroll wheel capability to Flash (AS2.0)

January 27, 2008 · 13 Comments

UPDATED VERSION CAN BE FOUND HERE :

http://mrsteel.wordpress.com/2008/07/31/mousecontrol-as2-class-update-added-mac-mouse-wheel-and-scrolling-area-support/

MouseControl class
for now just takes care of Mouse scroll wheel capability in Flash
MouseControl is Singleton class which lets you define movieclips and functions that should be invoked if user uses mouse scroll wheel over defined movie clip
it helps very much in situation when you need to define scrolling functionality in different classes of your Flash site or application

  • command addScroll(id, mc, function)
    example:
    MouseControl.getInstance().addScroll(”area1″, area1, Delegate.create(_root, moveFirst));
  • removeScroll(id)
    example:
    MouseControl.getInstance().removeScroll(”area1″);

example SWF : http://hagane.us/as/mousescroll/mousescroll.swf

source ZIP : http://hagane.us/as/mousescroll/MouseScroll.zip

I just also want to suggest that this is not correctly written Singleton class. Singleton classes should throw arror on attemp of basic class creation like:

var mouseControl = new MouseControl() ;

but mine is doing nothing, it is expecting that you use it correctly and that when you want to use class always use internal class instance (basic of Singleton), getting it with standard

var mouseControl = MouseControl.getInstance()

or with commands

MouseControl.getInstance().addScroll(id, mc, func)

avoiding doing proper Singleton is basiclly of AS2 which is not so strong typed language …
In AS3 I recommend you do proper Singleton - nice guide you can find on Grant Skinners blog

Categories: Actionscript 2 · Actionscript 2.0 · Flash · Flash _ · Tutorials · Web developer

13 responses so far ↓

Leave a Comment