package com.exanimo.controls { import com.exanimo.controls.DrawerDirection; import com.exanimo.controls.DrawerGroup; import fl.transitions.Tween; import fl.transitions.easing.*; import fl.transitions.TweenEvent; import flash.display.DisplayObjectContainer; import flash.display.InteractiveObject; import flash.display.Shape; import flash.display.Sprite; import flash.events.MouseEvent; import flash.events.Event; import flash.geom.Point; public class Drawer extends Sprite { private var _groupName:String; internal var _tab:InteractiveObject; public var isOpen:Boolean; public var obj:DisplayObjectContainer; /** * * Create a Drawer. * */ public function Drawer(obj:DisplayObjectContainer) { this.obj = obj; this.isOpen = false; this.groupName = 'DrawerGroup'; try { this.tab = obj.getChildByName('myTab') as InteractiveObject; } catch(error:Error) {} } // // get/set // /** * * Gets or sets the group to which this drawer belongs. All drawers are * created as part of the group named "DrawerGroup". * */ public function get group():DrawerGroup { return DrawerGroup.getGroup(this.groupName); } public function set group(group:DrawerGroup):void { this.group.removeDrawer(this); this._groupName = group.name; this.group.addDrawer(this); } /** * * Gets or sets the group to which this drawer belongs. All drawers are * created as part of the group named "DrawerGroup". If a drawer does not * exist with the specified name, it will be created and the drawer will * be added to it. * */ public function get groupName():String { return this._groupName; } public function set groupName(groupName:String):void { this.group = DrawerGroup.getGroup(groupName); this._groupName = groupName; } /** * * Gets or sets the InteractiveObject that will function as the tab for this * drawer. * */ public function get tab():InteractiveObject { return this._tab; } public function set tab(tab:InteractiveObject):void { if (tab) { tab.addEventListener(MouseEvent.CLICK, this._tabClickHandler); } this._tab = tab; } // // public // /** * * Open this drawer. * */ public function open():void { this.group.open(this); this.isOpen = true; this.dispatchEvent(new Event(Event.OPEN)); } /** * * Close this drawer. * */ public function close():void { this.group.close(); this.isOpen = false; this.dispatchEvent(new Event(Event.CLOSE)); } // // private // /** * * * */ private function _getXorY():String { switch(this.group.direction) { case DrawerDirection.UP: case DrawerDirection.DOWN: return 'y'; case DrawerDirection.LEFT: case DrawerDirection.RIGHT: return 'x'; default: throw new Error('Invalid Drawer direction value'); } } /** * * * */ private function _getWidthOrHeight():String { switch(this.group.direction) { case DrawerDirection.UP: case DrawerDirection.DOWN: return 'height'; case DrawerDirection.LEFT: case DrawerDirection.RIGHT: return 'width'; default: throw new Error('Invalid Drawer direction value'); } } /** * * * */ private function _tabClickHandler(e:MouseEvent = null):void { if (!this.isOpen) { this.open(); } else { this.close(); } } } }