It’s a pretty visually complex site, with lots of things going on and loads of mouse interaction in a plethora of different classes.
I’ve been struggling with the best and most efficient way to effectively “lock down” all mouse interaction in 70% of the objects when certain things happen. The best I could think of was to create a singelton that has a public setter. All the visual classes are listening to the Singelton and it dispatches Event.CHANGE when something happens which effectively triggers a lockdown in all the aux classes.
Is this … like… I mean. Will I go to Developer Hell for this? I can’t think of any ways that don’t include a LOT more code.
I like using a mixture of Singleton with something called a “semaphore”. Basically it acts as a lock, something as simple as…
package {
class Navigation {
private var _locked:Boolean = false;
public function Navigation() {}
public function isLocked():Boolean
{
return _locked;
}
public function lock():void
{
_locked = true;
}
public function unlock():void
{
_locked = false;
}
}
}
So not a true semaphore, but built off the same system, and you can obviously change this into a Singleton or a class that uses static methods. I just like it because a) it’s very very simple, and b) it logically makes sense.
mc.addEventListener( Event.CLICK, onClick );
function onClick( e:Event ):void
{
if ( !navigationInstance.isLocked() ) trace( "navigation is unlocked" );
}