topical media & game development
actionscript-events-ControlPanel.ax
actionscript-events-ControlPanel.ax
[swf]
flex
package {
import flash.display.*;
// A generic application that demonstrates the prevention of
// default behavior for custom events
public class @ax-actionscript-events-ControlPanel extends Sprite {
// Set this application user's privilege level. In this example, only
// users with UserType.ADMIN privileges can use the toggle switch.
private var userType:int = UserType.GUEST;
// Constructor
public function @ax-actionscript-events-ControlPanel () {
// Create a ToggleSwitch
var toggleSwitch:actionscript_events_ToggleSwitch = new actionscript_events_ToggleSwitch();
// Register for ToggleEvent.TOGGLE_ATTEMPT events
toggleSwitch.addEventListener(actionscript_events_ToggleEvent.TOGGLE_ATTEMPT,
toggleAttemptListener);
// Register for ToggleEvent.TOGGLE events
toggleSwitch.addEventListener(actionscript_events_ToggleEvent.TOGGLE,
toggleListener);
// Add the toggle switch to this object's display hierarchy
addChild(toggleSwitch);
}
// Listener executed whenever a ToggleEvent.TOGGLE_ATTEMPT event occurs
private function toggleAttemptListener (e:actionscript_events_ToggleEvent):void {
// If the user is a guest...
if (userType == actionscript_events_UserType.GUEST) {
// ...deny the attempted use of the toggle switch
e.preventDefault();
}
}
// Listener executed whenever a ToggleEvent.TOGGLE event occurs
private function toggleListener (e:ToggleEvent):void {
if (e.isOn) {
trace("The ToggleSwitch is now on.");
} else {
trace("The ToggleSwitch is now off.");
}
}
}
}
(C) Æliens
27/08/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.