Code for a resizable window in AS3

Flex handles window resizing really well so there is little need anymore to program your own custom window code. But for those of you who want a manually resizable window without loading some massive amount of flex code just to get resizable window code, I have provided a link to the FLA and Source Code. Scroll down to see the code in action and try resizing the dummy window I created. It has a minimum size set that you can change.

[Download Resizable Window Source Code Here](http://www.actionscript-flash-guru.com/example_files/resize_window_files.zip)

Important: you will have to change the class path of the FLA so that it can find the classes.


The example code below (see bottom of post) will get you up and running with a resizable window that you can drag and drop and resize. As you resize it, a custom resize event will be sent out it is in this function that you will add code that will resize the contents of the window accordingly. You will find the skinable assets inside of the FLA. I kept the ActionScript redundant so that the code would have as few function calls per resize iteration inorder to keep it efficient. The way it works is you mouse over the sides of the resize area and arrows will appear which indicates that you can drag them. It allows for dragging of all four corners and all four sides in addition to a place for the top bar on the window. So it functions like a resizable window on your desktop because you can drag the top bar around and the whole window changes position without resizing. I hope that you find this useful. If you are using flex you would be better off using their framework for a dragable window but like I said you have to bite off a lot if you want to do that. If you want to use flashes library for flashes standard UI components code by importing the "fl." package,

[(See more about the fl package)](http://www.actionscript-flash-guru.com/blog/14-flcontrols-not-found-how-do-i-import-the-fl-package)

you can do that but there are a lot of draw backs. One you import one class and you end up importing a whole bunch of stuff you may or may not use. This is a problem if you want to keep things super small. But the big thing that messes with me is the fact that you can't unload fl components if they have been loaded externally into a loader shell. This is because it does not have a listener clean up routine it simply relies on you building in a way that the user is going to leave the web page when he wants to dump the component. Finally, I have to share my annoyance with some of the pay components out there for resizable windows. They all have licenses that say you can only use their resizable window code per one website and they don't have a price for using it in software that is sold and redistributed, so this post is my protest to them.

Known problem's are listed at the bottom of the source code which may or may not apply to you depending on what you are developing.

//See a live example of this code (pre forked):
//http://www.actionscript-flash-guru.com/example_files/embed_scripts/resize_example.html
//You can download a full example of the original code SWFs (pre forked):
//http://www.actionscript-flash-guru.com/example_files/resize_window_files.zip
/************START EXAMPLE:****************/
//this bit of code relies on these classes (ResizeWindow and UiEvent) which I have listed below the code surrounded by END and START EXAMPLE
import com.actionscriptflashguru.ResizeWindow;
import com.actionscriptflashguru.UiEvent;
function onResizeUi(e:UiEvent):void{
var obj:Object = e.params;
//the new X and Y locations of the window
//obj.x;
//obj.y;
//the new width and height of the window
//obj.width;
//obj.height;
if (obj.isResizeAll != null){
//the window has not yet been initialized
thingToResize_mc.width = obj.width;
thingToResize_mc.height = obj.height;
thingToResize_mc.x = obj.x;
thingToResize_mc.y = obj.y;
trace("obj.isResizeAll != null");
} else {
thingToResize_mc.x = obj.x;
thingToResize_mc.y = obj.y;
thingToResize_mc.width = obj.width;
thingToResize_mc.height = obj.height;
}
}
var minWidth:Number = 300;
var minHeight:Number = 200;
var originalStageWidth:Number = this.stage.stageWidth;
var originalStageHeight:Number = this.stage.stageHeight;
var sizeObj:Object = {x:20, y:20, width:310, height:210};
resizer_mc.x = sizeObj.x;
resizer_mc.y = sizeObj.y;
thingToResize_mc.x = sizeObj.x+20;
thingToResize_mc.y = sizeObj.y+20;
thingToResize_mc.width = sizeObj.width;
thingToResize_mc.height = sizeObj.height;
var resizer:ResizeWindow = new ResizeWindow(resizer_mc, minWidth, minHeight, originalStageWidth, originalStageHeight);
//set the starting window size resizer.setSize(sizeObj.x, sizeObj.y, sizeObj.width, sizeObj.height);
resizer.addEventListener(UiEvent.RESIZE_WINDOW, onResizeUi);
/************:END EXAMPLE****************/
/************classes required to make this work are included in https://gist.github.com/nicholasdunbar/8794024****************/
package com.actionscriptflashguru {
//native libs
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.TextEvent;
import flash.events.EventDispatcher;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.external.ExternalInterface;
//my libs
import com.actionscriptflashguru.UiEvent;
public class ResizeWindow extends EventDispatcher{
//window container
private var _this:Sprite;
//resize cursors:
private var _iconTopLeft:Sprite;
private var _iconTopRight:Sprite;
private var _iconTop:Sprite;
private var _iconBottomLeft:Sprite;
private var _iconBottomRight:Sprite;
private var _iconBottom:Sprite;
private var _iconRight:Sprite;
private var _iconLeft:Sprite;
//resize hit zones
private var _barTop:Sprite;
private var _barBottom:Sprite;
private var _originalXBarBottom:Number;
private var _barRight:Sprite;
private var _originalYBarRight:Number;
private var _barLeft:Sprite;
private var _cornerBottomLeft:Sprite;
private var _cornerTopLeft:Sprite;
private var _cornerBottomRight:Sprite;
private var _cornerTopRight:Sprite;
//this is the bar that does no resizing it just moves the window around
private var _topMoveBar:Sprite;
//background
private var _bg:Sprite;
private var _originalYBg:Number;
private var _originalXBg:Number;
//drag states
private var _minWidth:Number;
private var _minHeight:Number;
private var _nativeWindowSizeHeight:Number;
private var _nativeWindowSizeWidth:Number;
private var _mysteryBox:Object;
private var _windowBounds:DisplayObject;
private var _isInit:Boolean;
//
private static const _HITZONE_FRAME_THICKNESS:int = 10;
private static const _FRAME_ALPHA:Number = 0.0;
public function ResizeWindow(d:DisplayObjectContainer, minWidth:Number, minHeight:Number, nativeWindowSizeWidth:Number = -1, nativeWindowSizeHeight:Number = -1):void {
_mysteryBox = d;
if (minWidth <= 0 || minHeight <= 0){
trace("minWidth or minHeight cannot be less than or equal to 0");
return;
}
_nativeWindowSizeWidth = nativeWindowSizeWidth;
_nativeWindowSizeHeight = nativeWindowSizeHeight;
_minWidth = minWidth;
_minHeight = minHeight;
//set resizer to visible
_this = d as Sprite;
_this.visible = false;
_this.alpha = 0;
if (_this.stage.stageWidth == 0 && _this.stage.stageHeight == 0){
_this.root.addEventListener(Event.ENTER_FRAME, _init);
} else {
_init();
}
}
public function destroy():void{
if (_this.root.hasEventListener(Event.ENTER_FRAME)){
_this.root.removeEventListener(Event.ENTER_FRAME, _init);
}
if (_barRight != null && _barRight.hasEventListener(MouseEvent.MOUSE_DOWN)){
_barRight.removeEventListener(MouseEvent.MOUSE_DOWN, _onRightDown);
}
if (_barRight != null && _barRight.hasEventListener(MouseEvent.MOUSE_UP)){
_barRight.removeEventListener(MouseEvent.MOUSE_UP, _onRightUp);
}
//TODO: need to remove the rest of the listeners
/*
_barRight.addEventListener(MouseEvent.MOUSE_MOVE, _onRightMove);
_barRight.addEventListener(MouseEvent.MOUSE_OUT, _onRightOut);
_barBottom.addEventListener(MouseEvent.MOUSE_DOWN, _onBottomDown);
_barBottom.addEventListener(MouseEvent.MOUSE_UP, _onBottomUp);
_barBottom.addEventListener(MouseEvent.MOUSE_MOVE, _onBottomMove);
_barBottom.addEventListener(MouseEvent.MOUSE_OUT, _onBottomOut);
_cornerBottomRight.addEventListener(MouseEvent.MOUSE_DOWN, _onBottomRightDown);
_cornerBottomRight.addEventListener(MouseEvent.MOUSE_UP, _onBottomRightUp);
_cornerBottomRight.addEventListener(MouseEvent.MOUSE_MOVE, _onBottomRightOver);
_cornerBottomRight.addEventListener(MouseEvent.MOUSE_OUT, _onBottomRightOut);
_barLeft.addEventListener(MouseEvent.MOUSE_DOWN, _onLeftDown);
_barLeft.addEventListener(MouseEvent.MOUSE_UP, _onLeftUp);
_barLeft.addEventListener(MouseEvent.MOUSE_MOVE, _onLeftMove);
_barLeft.addEventListener(MouseEvent.MOUSE_OUT, _onLeftOut);
_cornerBottomLeft.addEventListener(MouseEvent.MOUSE_DOWN, _onBottomLeftDown);
_cornerBottomLeft.addEventListener(MouseEvent.MOUSE_UP, _onBottomLeftUp);
_cornerBottomLeft.addEventListener(MouseEvent.MOUSE_MOVE, _onBottomLeftOver);
_cornerBottomLeft.addEventListener(MouseEvent.MOUSE_OUT, _onBottomLeftOut);
_barTop.addEventListener(MouseEvent.MOUSE_DOWN, _onTopDown);
_barTop.addEventListener(MouseEvent.MOUSE_UP, _onTopUp);
_barTop.addEventListener(MouseEvent.MOUSE_MOVE, _onTopMove);
_barTop.addEventListener(MouseEvent.MOUSE_OUT, _onTopOut);
_cornerTopLeft.addEventListener(MouseEvent.MOUSE_DOWN, _onTopLeftDown);
_cornerTopLeft.addEventListener(MouseEvent.MOUSE_UP, _onTopLeftUp);
_cornerTopLeft.addEventListener(MouseEvent.MOUSE_MOVE, _onTopLeftOver);
_cornerTopLeft.addEventListener(MouseEvent.MOUSE_OUT, _onTopLeftOut);
_cornerTopRight.addEventListener(MouseEvent.MOUSE_DOWN, _onTopRightDown);
_cornerTopRight.addEventListener(MouseEvent.MOUSE_UP, _onTopRightUp);
_cornerTopRight.addEventListener(MouseEvent.MOUSE_MOVE, _onTopRightOver);
_cornerTopRight.addEventListener(MouseEvent.MOUSE_OUT, _onTopRightOut);
_topMoveBar.addEventListener(MouseEvent.MOUSE_DOWN, _onTopMoveDown);
_topMoveBar.addEventListener(MouseEvent.MOUSE_UP, _onTopMoveUp);
_topMoveBar.buttonMode = true;
_topMoveBar.useHandCursor = true;
*/
}
public function updateLimits(xWidth:Number, yHeight:Number):void{
_nativeWindowSizeWidth = xWidth;
_nativeWindowSizeHeight = yHeight;
}
public function setSize(x:Number, y:Number, width:Number, height:Number):void {
if (!_isInit) {
trace("Error: can't set size untill the ResizeWindow has been initialized");
return;
}
//set up thresholds
_bg.x = x;
_bg.y = y;
_bg.width = width;
_bg.height = height;
_originalXBarBottom = _bg.x+_HITZONE_FRAME_THICKNESS;
_originalYBarRight = _bg.y+_HITZONE_FRAME_THICKNESS;
_originalXBg = _bg.x;
_originalYBg = _bg.y;
//set up hit zones
//right hitzone
_barRight.y = _originalYBarRight;
_barRight.x = _bg.width+_bg.x-(_HITZONE_FRAME_THICKNESS/2);
_iconRight.visible = false;
_iconRight.x = _barRight.x;
_barRight.graphics.clear();
_barRight.graphics.beginFill(0, _FRAME_ALPHA);
_barRight.graphics.drawRect(0,0,_HITZONE_FRAME_THICKNESS,_bg.height-(2*_HITZONE_FRAME_THICKNESS));
_barRight.graphics.endFill();
//bottom hitzone
_barBottom.x = _originalXBarBottom;
_barBottom.y = _bg.height+_bg.y-(_HITZONE_FRAME_THICKNESS/2);
_iconBottom.visible = false;
_iconBottom.y = _barBottom.y;
_barBottom.graphics.clear();
_barBottom.graphics.beginFill(0, _FRAME_ALPHA);
_barBottom.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS);
_barBottom.graphics.endFill();
//left hit zone
_barLeft.y = _originalYBarRight;
_barLeft.x = _bg.x-(_HITZONE_FRAME_THICKNESS/2);
_iconLeft.visible = false;
_iconLeft.x = _bg.x;
_barLeft.graphics.clear();
_barLeft.graphics.beginFill(0, _FRAME_ALPHA);
_barLeft.graphics.drawRect(0,0,_HITZONE_FRAME_THICKNESS,_bg.height-(_barLeft.y - _bg.y)-_HITZONE_FRAME_THICKNESS);
_barLeft.graphics.endFill();
//top hitzone
_barTop.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_barTop.y = _bg.y-(_HITZONE_FRAME_THICKNESS/2);
_iconTop.visible = false;
_iconTop.y = _barTop.y;
_barTop.graphics.clear();
_barTop.graphics.beginFill(0, _FRAME_ALPHA);
_barTop.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS);
_barTop.graphics.endFill();
//top drag bar hit zone
_topMoveBar.y = _bg.y+(_HITZONE_FRAME_THICKNESS/2);
_topMoveBar.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_topMoveBar.graphics.clear();
_topMoveBar.graphics.beginFill(0, _FRAME_ALPHA);
_topMoveBar.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS*2);
_topMoveBar.graphics.endFill();
//set corners to the correct places
_cornerTopRight.x = _bg.x+_bg.width;
_cornerTopRight.y = _bg.y;
_cornerTopRight.alpha = _FRAME_ALPHA;
_cornerTopLeft.x = _bg.x;
_cornerTopLeft.y = _bg.y;
_cornerTopLeft.alpha = _FRAME_ALPHA;
_cornerBottomRight.x = _bg.x+_bg.width;
_cornerBottomRight.y = _bg.y+_bg.height;
_cornerBottomRight.alpha = _FRAME_ALPHA;
_cornerBottomLeft.x = _bg.x;
_cornerBottomLeft.y = _bg.y+_bg.height;
_cornerBottomLeft.alpha = _FRAME_ALPHA;
}
public function getWidth():Number{
return _bg.width*_this.scaleX;
}
public function getHeight():Number{
return _bg.height*_this.scaleY;
}
public function getX():Number{
return _bg.x+_this.x;
}
public function getY():Number{
return _bg.y+_this.y;
}
private function _init(e:Event = null):void{
var rectangle:Rectangle;
var bottomRight:Point;
//make sure stage sizes have been updated
if (_this.stage.stageWidth == 0 && _this.stage.stageHeight == 0){
return;
}
/*
//calculate container scale
var containerScale:Number = 1;
if (_nativeWindowSizeWidth < _this.root.stage.stageWidth && _nativeWindowSizeHeight > _this.root.stage.stageHeight){
containerScale = (_nativeWindowSizeHeight/_this.root.stage.stageHeight);
} else if (_nativeWindowSizeWidth < _this.root.stage.stageWidth && _nativeWindowSizeHeight < _this.root.stage.stageHeight) {
containerScale = (_nativeWindowSizeWidth/_this.root.stage.stageWidth);
} else if (_nativeWindowSizeWidth < _this.root.stage.stageWidth && _nativeWindowSizeHeight < _this.root.stage.stageHeight){
//whole square is bigger than original
if (_this.root.stage.stageWidth <= _this.root.stage.stageHeight){
containerScale = (_this.root.stage.stageWidth/_nativeWindowSizeWidth);
} else {
containerScale = (_this.root.stage.stageHeight/_nativeWindowSizeHeight);
}
} else if (_nativeWindowSizeWidth > _this.root.stage.stageWidth && _nativeWindowSizeHeight > _this.root.stage.stageHeight){
//whole square is less than original
if (_this.root.stage.stageWidth <= _this.root.stage.stageHeight){
containerScale = (_this.root.stage.stageWidth/_nativeWindowSizeWidth);
} else {
containerScale = (_this.root.stage.stageHeight/_nativeWindowSizeHeight);
}
}*/
if (_this.root.hasEventListener(Event.ENTER_FRAME)){
_this.root.removeEventListener(Event.ENTER_FRAME, _init);
}
//get all the assets
//get resize cursors:
_iconTopLeft = _mysteryBox.iconTopLeft_mc
if (_iconTopLeft == null){
trace("Error: asset iconTopLeft_mc not found in resize window");
return;
}
_iconTopLeft.visible = false;
_iconTopRight = _mysteryBox.iconTopRight_mc
if (_iconTopRight == null){
trace("Error: asset iconTopRight_mc not found in resize window");
return;
}
_iconTopRight.visible = false;
_iconTop = _mysteryBox.iconTop_mc
if (_iconTop == null){
trace("Error: asset iconTop_mc not found in resize window");
return;
}
_iconTop.visible = false;
_iconBottomLeft = _mysteryBox.iconBottomLeft_mc
if (_iconBottomLeft == null){
trace("Error: asset iconBottomLeft_mc not found in resize window");
return;
}
_iconBottomLeft.visible = false;
_iconBottomRight = _mysteryBox.iconBottomRight_mc
if (_iconBottomRight == null){
trace("Error: asset iconBottomRight_mc not found in resize window");
return;
}
_iconBottomRight.visible = false;
_iconBottom = _mysteryBox.iconBottom_mc
if (_iconBottom == null){
trace("Error: asset iconBottom_mc not found in resize window");
return;
}
_iconBottom.visible = false;
_iconRight = _mysteryBox.iconRight_mc
if (_iconRight == null){
trace("Error: asset iconRight_mc not found in resize window");
return;
}
_iconRight.visible = false;
_iconLeft = _mysteryBox.iconLeft_mc
if (_iconLeft == null){
trace("Error: asset iconLeft_mc not found in resize window");
return;
}
_iconLeft.visible = false;
//get the resize hit zones
_barTop = _mysteryBox.barTop_mc
if (_barTop == null){
trace("Error: asset barTop_mc not found in resize window");
return;
}
_barBottom = _mysteryBox.barBottom_mc
if (_barBottom == null){
trace("Error: asset barBottom_mc not found in resize window");
return;
}
_barRight = _mysteryBox.barRight_mc
if (_barRight == null){
trace("Error: asset barRight_mc not found in resize window");
return;
}
_barLeft = _mysteryBox.barLeft_mc
if (_barLeft == null){
trace("Error: asset barLeft_mc not found in resize window");
return;
}
_cornerBottomLeft = _mysteryBox.cornerBottomLeft_mc
if (_cornerBottomLeft == null){
trace("Error: asset cornerBottomLeft_mc not found in resize window");
return;
}
_cornerTopLeft = _mysteryBox.cornerTopLeft_mc
if (_cornerTopLeft == null){
trace("Error: asset cornerTopLeft_mc not found in resize window");
return;
}
_cornerBottomRight = _mysteryBox.cornerBottomRight_mc
if (_cornerBottomRight == null){
trace("Error: asset cornerBottomRight_mc not found in resize window");
return;
}
_cornerTopRight = _mysteryBox.cornerTopRight_mc
if (_cornerTopRight == null){
trace("Error: asset cornerTopRight_mc not found in resize window");
return;
}
_topMoveBar = _mysteryBox.topMoveBar_mc
if (_topMoveBar == null){
trace("Error: asset topMoveBar_mc not found in resize window");
return;
}
//get background
_bg = _mysteryBox.bg_mc
if (_bg == null){
trace("Error: asset bg_mc not found in resize window");
return;
}
//set up thresholds
_originalXBarBottom = _bg.x+_HITZONE_FRAME_THICKNESS;
_originalYBarRight = _bg.y+_HITZONE_FRAME_THICKNESS;
_originalXBg = _bg.x;
_originalYBg = _bg.y;
//set up hit zones
//right hitzone
_barRight.y = _originalYBarRight;
_barRight.x = _bg.width+_bg.x-(_HITZONE_FRAME_THICKNESS/2);
_iconRight.visible = false;
_iconRight.x = _barRight.x;
_barRight.graphics.clear();
_barRight.graphics.beginFill(0, _FRAME_ALPHA);
_barRight.graphics.drawRect(0,0,_HITZONE_FRAME_THICKNESS,_bg.height-(2*_HITZONE_FRAME_THICKNESS));
_barRight.graphics.endFill();
//bottom hitzone
_barBottom.x = _originalXBarBottom;
_barBottom.y = _bg.height+_bg.y-(_HITZONE_FRAME_THICKNESS/2);
_iconBottom.visible = false;
_iconBottom.y = _barBottom.y;
_barBottom.graphics.clear();
_barBottom.graphics.beginFill(0, _FRAME_ALPHA);
_barBottom.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS);
_barBottom.graphics.endFill();
//left hit zone
_barLeft.y = _originalYBarRight;
_barLeft.x = _bg.x-(_HITZONE_FRAME_THICKNESS/2);
_iconLeft.visible = false;
_iconLeft.x = _bg.x;
_barLeft.graphics.clear();
_barLeft.graphics.beginFill(0, _FRAME_ALPHA);
_barLeft.graphics.drawRect(0,0,_HITZONE_FRAME_THICKNESS,_bg.height-(_barLeft.y - _bg.y)-_HITZONE_FRAME_THICKNESS);
_barLeft.graphics.endFill();
//top hitzone
_barTop.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_barTop.y = _bg.y-(_HITZONE_FRAME_THICKNESS/2);
_iconTop.visible = false;
_iconTop.y = _barTop.y;
_barTop.graphics.clear();
_barTop.graphics.beginFill(0, _FRAME_ALPHA);
_barTop.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS);
_barTop.graphics.endFill();
//top drag bar hit zone
_topMoveBar.y = _bg.y+(_HITZONE_FRAME_THICKNESS/2);
_topMoveBar.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_topMoveBar.graphics.clear();
_topMoveBar.graphics.beginFill(0, _FRAME_ALPHA);
_topMoveBar.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS*2);
_topMoveBar.graphics.endFill();
//set corners to the correct places
_cornerTopRight.x = _bg.x+_bg.width;
_cornerTopRight.y = _bg.y;
_cornerTopRight.alpha = _FRAME_ALPHA;
_cornerTopLeft.x = _bg.x;
_cornerTopLeft.y = _bg.y;
_cornerTopLeft.alpha = _FRAME_ALPHA;
_cornerBottomRight.x = _bg.x+_bg.width;
_cornerBottomRight.y = _bg.y+_bg.height;
_cornerBottomRight.alpha = _FRAME_ALPHA;
_cornerBottomLeft.x = _bg.x;
_cornerBottomLeft.y = _bg.y+_bg.height;
_cornerBottomLeft.alpha = _FRAME_ALPHA;
//set listeners.
_barRight.addEventListener(MouseEvent.MOUSE_DOWN, _onRightDown);
_barRight.addEventListener(MouseEvent.MOUSE_UP, _onRightUp);
_barRight.addEventListener(MouseEvent.MOUSE_MOVE, _onRightMove);
_barRight.addEventListener(MouseEvent.MOUSE_OUT, _onRightOut);
_barBottom.addEventListener(MouseEvent.MOUSE_DOWN, _onBottomDown);
_barBottom.addEventListener(MouseEvent.MOUSE_UP, _onBottomUp);
_barBottom.addEventListener(MouseEvent.MOUSE_MOVE, _onBottomMove);
_barBottom.addEventListener(MouseEvent.MOUSE_OUT, _onBottomOut);
_cornerBottomRight.addEventListener(MouseEvent.MOUSE_DOWN, _onBottomRightDown);
_cornerBottomRight.addEventListener(MouseEvent.MOUSE_UP, _onBottomRightUp);
_cornerBottomRight.addEventListener(MouseEvent.MOUSE_MOVE, _onBottomRightOver);
_cornerBottomRight.addEventListener(MouseEvent.MOUSE_OUT, _onBottomRightOut);
_barLeft.addEventListener(MouseEvent.MOUSE_DOWN, _onLeftDown);
_barLeft.addEventListener(MouseEvent.MOUSE_UP, _onLeftUp);
_barLeft.addEventListener(MouseEvent.MOUSE_MOVE, _onLeftMove);
_barLeft.addEventListener(MouseEvent.MOUSE_OUT, _onLeftOut);
_cornerBottomLeft.addEventListener(MouseEvent.MOUSE_DOWN, _onBottomLeftDown);
_cornerBottomLeft.addEventListener(MouseEvent.MOUSE_UP, _onBottomLeftUp);
_cornerBottomLeft.addEventListener(MouseEvent.MOUSE_MOVE, _onBottomLeftOver);
_cornerBottomLeft.addEventListener(MouseEvent.MOUSE_OUT, _onBottomLeftOut);
_barTop.addEventListener(MouseEvent.MOUSE_DOWN, _onTopDown);
_barTop.addEventListener(MouseEvent.MOUSE_UP, _onTopUp);
_barTop.addEventListener(MouseEvent.MOUSE_MOVE, _onTopMove);
_barTop.addEventListener(MouseEvent.MOUSE_OUT, _onTopOut);
_cornerTopLeft.addEventListener(MouseEvent.MOUSE_DOWN, _onTopLeftDown);
_cornerTopLeft.addEventListener(MouseEvent.MOUSE_UP, _onTopLeftUp);
_cornerTopLeft.addEventListener(MouseEvent.MOUSE_MOVE, _onTopLeftOver);
_cornerTopLeft.addEventListener(MouseEvent.MOUSE_OUT, _onTopLeftOut);
_cornerTopRight.addEventListener(MouseEvent.MOUSE_DOWN, _onTopRightDown);
_cornerTopRight.addEventListener(MouseEvent.MOUSE_UP, _onTopRightUp);
_cornerTopRight.addEventListener(MouseEvent.MOUSE_MOVE, _onTopRightOver);
_cornerTopRight.addEventListener(MouseEvent.MOUSE_OUT, _onTopRightOut);
_topMoveBar.addEventListener(MouseEvent.MOUSE_DOWN, _onTopMoveDown);
_topMoveBar.addEventListener(MouseEvent.MOUSE_UP, _onTopMoveUp);
_topMoveBar.buttonMode = true;
_topMoveBar.useHandCursor = true;
_this.visible = true;
_this.alpha = 1;
_isInit = true;
}
/*********************Right HitZone***************************/
private function _onRightDown(e:MouseEvent):void{
_iconRight.visible = true;
_iconRight.y = e.localY+e.currentTarget.y;
_iconRight.x = _barRight.x;
_barTop.visible = false;
_barLeft.visible = false;
_barBottom.visible = false; _topMoveBar.visible=false;
_cornerBottomLeft.visible = false;
_cornerBottomRight.visible = false;
_cornerTopLeft.visible = false;
_cornerTopRight.visible = false;
_barRight.parent.addEventListener(MouseEvent.MOUSE_MOVE, _mouseRightMoveHandler);
_barRight.parent.stage.addEventListener(Event.MOUSE_LEAVE, _onRightLeavesMovie);
_barRight.startDrag();
}
private function _onRightLeavesMovie(e:Event){
_onRightUp();
}
private function _mouseRightMoveHandler(e:MouseEvent = null):void {
var newWidth:Number;
var limitedCoords:Point;
//check to make sure this is not out of bounds
limitedCoords = _keepInBounds(_barRight.x,_barRight.y);
newWidth = limitedCoords.x-_bg.x+(_HITZONE_FRAME_THICKNESS/2);
if (newWidth > _minWidth ){
_bg.width = newWidth;
_iconRight.x = _bg.x+_bg.width;
}
_cornerBottomRight.x = _iconRight.x;
_cornerTopRight.x = _iconRight.x;
_barBottom.graphics.clear();
_barBottom.graphics.beginFill(0, _FRAME_ALPHA);
_barBottom.graphics.drawRect(0, 0, _bg.width-(_barBottom.x - _bg.x)-_HITZONE_FRAME_THICKNESS, _HITZONE_FRAME_THICKNESS);
_barBottom.graphics.endFill();
_barTop.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_barTop.y = _bg.y-(_HITZONE_FRAME_THICKNESS/2);
_iconTop.visible = false;
_iconTop.y = _barTop.y;
_barTop.graphics.clear();
_barTop.graphics.beginFill(0, _FRAME_ALPHA);
_barTop.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS);
_barTop.graphics.endFill();
_topMoveBar.y = _bg.y+(_HITZONE_FRAME_THICKNESS/2);
_topMoveBar.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_topMoveBar.graphics.clear();
_topMoveBar.graphics.beginFill(0, _FRAME_ALPHA);
_topMoveBar.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS*2);
_topMoveBar.graphics.endFill();
this.dispatchEvent( new UiEvent(UiEvent.RESIZE_WINDOW, {x:_bg.x+_this.x, y:_bg.y+_this.y, width:_bg.width*_this.scaleX, height:_bg.height*_this.scaleY}, false, true) );
if (e != null){
e.updateAfterEvent();
}
}
private function _onRightMove(e:MouseEvent):void{
var newY:Number;
newY = e.localY+e.currentTarget.y;
_iconRight.visible = true;
if (newY > _bg.y+_HITZONE_FRAME_THICKNESS && newY < _bg.height+_bg.y-_HITZONE_FRAME_THICKNESS){
_iconRight.y = newY;
}
_iconRight.x = _bg.x+_bg.width;
}
private function _onRightOut(e:MouseEvent):void{
_iconRight.visible = false;
}
private function _onRightUp(e:MouseEvent = null):void{
_mouseRightMoveHandler();
_barTop.visible = true;
_barLeft.visible = true;
_barBottom.visible = true; _topMoveBar.visible=true;
_cornerBottomLeft.visible = true;
_cornerBottomRight.visible = true;
_cornerTopLeft.visible = true;
_cornerTopRight.visible = true;
_barRight.y = _bg.y+_HITZONE_FRAME_THICKNESS;
_barRight.x = _bg.x+_bg.width-(_HITZONE_FRAME_THICKNESS/2);
_barRight.parent.removeEventListener(MouseEvent.MOUSE_MOVE, _mouseRightMoveHandler);
_barRight.parent.stage.removeEventListener(Event.MOUSE_LEAVE, _onRightLeavesMovie);
_barRight.stopDrag();
}
/*********************Bottom HitZone***************************/
private function _onBottomDown(e:MouseEvent):void{
_iconBottom.visible = true;
_iconBottom.y = _barBottom.y;
_barRight.visible = false;
_barTop.visible = false;
_barLeft.visible = false;
_cornerBottomLeft.visible = false;
_cornerBottomRight.visible = false;
_cornerTopLeft.visible = false;
_cornerTopRight.visible = false;
_topMoveBar.visible = false;
_cornerBottomRight.removeEventListener(MouseEvent.MOUSE_MOVE, _onBottomRightOver);
_barRight.removeEventListener(MouseEvent.MOUSE_MOVE, _onRightMove);
_barBottom.parent.addEventListener(MouseEvent.MOUSE_MOVE, _mouseBottomMoveHandler);
_barBottom.parent.stage.addEventListener(Event.MOUSE_LEAVE, _onBottomLeavesMovie);
_barBottom.startDrag();
}
private function _onBottomLeavesMovie(e:Event){
_onBottomUp();
}
private function _mouseBottomMoveHandler(e:MouseEvent = null):void {
var newHeight:Number;
var limitedCoords:Point;
//check to make sure this is not out of bounds
limitedCoords = _keepInBounds(_barBottom.x,_barBottom.y);
newHeight = limitedCoords.y-_bg.y+(_HITZONE_FRAME_THICKNESS/2);
if (newHeight > _minHeight ){
_bg.height = newHeight;
} else {
_bg.height = _minHeight;
}
_iconBottom.y = _bg.y+_bg.height;
_cornerBottomRight.y = _iconBottom.y;
_cornerBottomLeft.y = _iconBottom.y;
_barRight.graphics.clear();
_barRight.graphics.beginFill(0, _FRAME_ALPHA);
_barRight.graphics.drawRect(0,0,_HITZONE_FRAME_THICKNESS,_bg.height-(_barRight.y - _bg.y)-_HITZONE_FRAME_THICKNESS);
_barRight.graphics.endFill();
_barLeft.graphics.clear();
_barLeft.graphics.beginFill(0, _FRAME_ALPHA);
_barLeft.graphics.drawRect(0, 0, _HITZONE_FRAME_THICKNESS, _bg.height-(2*_HITZONE_FRAME_THICKNESS));
_barLeft.graphics.endFill();
this.dispatchEvent( new UiEvent(UiEvent.RESIZE_WINDOW, {x:_bg.x+_this.x, y:_bg.y+_this.y, width:_bg.width*_this.scaleX, height:_bg.height*_this.scaleY}, false, true) );
if (e != null){
e.updateAfterEvent();
}
}
private function _onBottomMove(e:MouseEvent):void{
var newX:Number;
newX = e.localX+e.currentTarget.x;
if (newX > _bg.x+_HITZONE_FRAME_THICKNESS && newX < _bg.width+_bg.x-_HITZONE_FRAME_THICKNESS){
_iconBottom.x = newX;
_iconBottom.visible = true;
} else if (newX > _bg.width+_bg.x-_HITZONE_FRAME_THICKNESS) {
_iconBottom.x = _bg.x+_bg.width-_HITZONE_FRAME_THICKNESS;
_iconBottom.visible = true;
} else if (newX < _bg.x+_HITZONE_FRAME_THICKNESS){
_iconBottom.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_iconBottom.visible = true;
}
_iconBottom.y = _bg.y+_bg.height;
}
private function _onBottomOut(e:MouseEvent):void{
_iconBottom.visible = false;
}
private function _onBottomUp(e:MouseEvent = null):void{
_mouseBottomMoveHandler();
_iconBottom.visible = false;
_barBottom.y = _bg.height+_bg.y-(_HITZONE_FRAME_THICKNESS/2);
_barBottom.x = _bg.x+(_HITZONE_FRAME_THICKNESS);
_iconBottom.y = _barBottom.y;
_cornerBottomRight.y = _bg.y+_bg.height;
_cornerBottomLeft.y = _bg.y+_bg.height;
_barRight.visible = true;
_barTop.visible = true; _topMoveBar.visible=true;
_barLeft.visible = true;
_cornerBottomLeft.visible = true;
_cornerBottomRight.visible = true;
_cornerTopLeft.visible = true;
_cornerTopRight.visible = true;
_topMoveBar.visible = true;
_cornerBottomRight.addEventListener(MouseEvent.MOUSE_MOVE, _onBottomRightOver);
_barRight.addEventListener(MouseEvent.MOUSE_MOVE, _onRightMove);
_barBottom.parent.removeEventListener(MouseEvent.MOUSE_MOVE, _mouseBottomMoveHandler);
_barBottom.parent.stage.removeEventListener(Event.MOUSE_LEAVE, _onBottomLeavesMovie);
_barBottom.stopDrag();
}
/*********************Bottom Right Corner HitZone***************************/
private function _onBottomRightDown(e:MouseEvent):void{
_iconBottomRight.x = _cornerBottomRight.x;
_iconBottomRight.y = _cornerBottomRight.y;
_barBottom.visible = false; _topMoveBar.visible=false;
_barRight.visible = false;
_barTop.visible = false;
_barLeft.visible = false;
_cornerBottomLeft.visible = false;
_cornerTopLeft.visible = false;
_cornerTopRight.visible = false;
_cornerBottomRight.parent.addEventListener(MouseEvent.MOUSE_MOVE, _mouseBottomRightMoveHandler);
_cornerBottomRight.parent.stage.addEventListener(Event.MOUSE_LEAVE, _onBottomRightLeavesMovie);
_cornerBottomRight.startDrag();
}
private function _onBottomRightUp(e:MouseEvent = null):void{
_mouseBottomRightMoveHandler();
_barRight.x = _bg.width+_bg.x-(_HITZONE_FRAME_THICKNESS/2);
_iconRight.y = _cornerBottomRight.y;
_barRight.x = _bg.width+_bg.x-(_HITZONE_FRAME_THICKNESS/2);
_iconRight.x = _cornerBottomRight.x;
_iconBottomRight.x = _bg.width+_bg.x;
_iconBottomRight.y = _bg.height+_bg.y;
_barTop.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_barTop.y = _bg.y-(_HITZONE_FRAME_THICKNESS/2);
_iconTop.visible = false;
_iconTop.y = _barTop.y;
_cornerBottomRight.x = _bg.width+_bg.x;
_cornerBottomRight.y = _bg.height+_bg.y;
_cornerBottomLeft.y = _cornerBottomRight.y;
_cornerBottomLeft.x = _bg.x;
_cornerTopRight.x = _bg.x+_bg.width;
_topMoveBar.y = _bg.y+(_HITZONE_FRAME_THICKNESS/2);
_topMoveBar.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_iconRight.x = _cornerBottomRight.x;
_iconBottom.y = _cornerBottomRight.y;
_barBottom.visible = true; _topMoveBar.visible=true;
_barRight.visible = true;
_barTop.visible = true;
_barLeft.visible = true;
_cornerBottomLeft.visible = true;
_cornerTopLeft.visible = true;
_cornerTopRight.visible = true;
_cornerBottomRight.parent.removeEventListener(MouseEvent.MOUSE_MOVE, _mouseBottomRightMoveHandler);
_cornerBottomRight.parent.stage.removeEventListener(Event.MOUSE_LEAVE, _onBottomRightLeavesMovie);
_cornerBottomRight.stopDrag();
}
private function _mouseBottomRightMoveHandler(e:MouseEvent = null):void{
var newHeight:Number;
var newWidth:Number;
var limitedCoords:Point;
//check to make sure this is not out of bounds
limitedCoords = _keepInBounds(_cornerBottomRight.x,_cornerBottomRight.y);
newHeight = limitedCoords.y-_bg.y;
if (newHeight > _minHeight ){
_bg.height = newHeight;
} else {
_bg.height = _minHeight;
}
_barBottom.y = _bg.height+_bg.y-(_HITZONE_FRAME_THICKNESS/2);
newWidth = limitedCoords.x-_bg.x;
if (newWidth > _minWidth ){
_bg.width = newWidth;
} else {
_bg.width = _minWidth;
}
_barRight.x = _bg.width+_bg.x-(_HITZONE_FRAME_THICKNESS/2);
_iconRight.y = limitedCoords.y;
_barRight.graphics.clear();
_barRight.graphics.beginFill(0, _FRAME_ALPHA);
_barRight.graphics.drawRect(0, 0, _HITZONE_FRAME_THICKNESS, _bg.height-(2*_HITZONE_FRAME_THICKNESS));
_barRight.graphics.endFill();
_iconRight.x = limitedCoords.x;
_iconBottom.y = limitedCoords.y;
_barBottom.graphics.clear();
_barBottom.graphics.beginFill(0, _FRAME_ALPHA);
_barBottom.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS);
_barBottom.graphics.endFill();
_barTop.graphics.clear();
_barTop.graphics.beginFill(0, _FRAME_ALPHA);
_barTop.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS);
_barTop.graphics.endFill();
_iconBottomRight.x = _bg.width+_bg.x;
_iconBottomRight.y = _bg.height+_bg.y;
_cornerBottomLeft.y = limitedCoords.y;
_cornerBottomLeft.x = _bg.x;
_cornerTopRight.x = _bg.x+_bg.width;
_barLeft.graphics.clear();
_barLeft.graphics.beginFill(0, _FRAME_ALPHA);
_barLeft.graphics.drawRect(0, 0, _HITZONE_FRAME_THICKNESS, _bg.height-(2*_HITZONE_FRAME_THICKNESS));
_barLeft.graphics.endFill();
_topMoveBar.y = _bg.y+(_HITZONE_FRAME_THICKNESS/2);
_topMoveBar.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_topMoveBar.graphics.clear();
_topMoveBar.graphics.beginFill(0, _FRAME_ALPHA);
_topMoveBar.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS*2);
_topMoveBar.graphics.endFill();
this.dispatchEvent( new UiEvent(UiEvent.RESIZE_WINDOW, {x:_bg.x+_this.x, y:_bg.y+_this.y, width:_bg.width*_this.scaleX, height:_bg.height*_this.scaleY}, false, true) );
if (e != null){
e.updateAfterEvent();
}
}
private function _onBottomRightLeavesMovie(e:Event):void{
_onBottomRightUp();
}
private function _onBottomRightOver(e:MouseEvent):void{
_iconBottomRight.x = _cornerBottomRight.x;
_iconBottomRight.y = _cornerBottomRight.y;
_iconBottomRight.visible = true;
}
private function _onBottomRightOut(e:MouseEvent):void{
_iconBottomRight.x = _cornerBottomRight.x;
_iconBottomRight.y = _cornerBottomRight.y;
_iconBottomRight.visible = false;
}
/*********************Left HitZone***************************/
private function _onLeftDown(e:MouseEvent):void{
_originalXBg = _bg.x;
_originalYBg = _bg.y;
_barTop.visible = false;
_barRight.visible = false;
_barBottom.visible = false; _topMoveBar.visible=false;
_cornerBottomLeft.visible = false;
_cornerBottomRight.visible = false;
_cornerTopLeft.visible = false;
_cornerTopRight.visible = false;
_barLeft.parent.addEventListener(MouseEvent.MOUSE_MOVE, _mouseLeftMoveHandler);
_barLeft.parent.stage.addEventListener(Event.MOUSE_LEAVE, _onLeftLeavesMovie);
_barLeft.startDrag();
}
private function _onLeftLeavesMovie(e:Event){
_onLeftUp();
}
private function _mouseLeftMoveHandler(e:MouseEvent = null):void {
var newWidth:Number;
var limitedCoords:Point;
//check to make sure this is not out of bounds
limitedCoords = _keepInBounds(_barLeft.x,_barLeft.y);
var distanceMoved:Number = (limitedCoords.x-_bg.x+(_HITZONE_FRAME_THICKNESS/2));
newWidth = _bg.width-distanceMoved;
if (newWidth > _minWidth ){
_bg.width = newWidth;
_bg.x = _bg.x+distanceMoved;
_iconLeft.x = _bg.x;
} else {
distanceMoved = _bg.width-_minWidth;
_bg.width = _minWidth;
_bg.x = _bg.x+distanceMoved;
_iconLeft.x = _bg.x;
}
_cornerBottomLeft.x = _bg.x;
_cornerBottomLeft.y = _bg.y+_bg.height;
_cornerTopLeft.x = _bg.x;
_cornerTopLeft.y = _bg.y;
_barBottom.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_barBottom.graphics.clear();
_barBottom.graphics.beginFill(0, _FRAME_ALPHA);
_barBottom.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS);
_barBottom.graphics.endFill();
_barTop.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_barTop.y = _bg.y-(_HITZONE_FRAME_THICKNESS/2);
_iconTop.visible = false;
_iconTop.y = _barTop.y;
_barTop.graphics.clear();
_barTop.graphics.beginFill(0, _FRAME_ALPHA);
_barTop.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS);
_barTop.graphics.endFill();
_topMoveBar.y = _bg.y+(_HITZONE_FRAME_THICKNESS/2);
_topMoveBar.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_topMoveBar.graphics.clear();
_topMoveBar.graphics.beginFill(0, _FRAME_ALPHA);
_topMoveBar.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS*2);
_topMoveBar.graphics.endFill();
this.dispatchEvent( new UiEvent(UiEvent.RESIZE_WINDOW, {x:_bg.x+_this.x, y:_bg.y+_this.y, width:_bg.width*_this.scaleX, height:_bg.height*_this.scaleY}, false, true) );
if (e != null){
e.updateAfterEvent();
}
}
private function _onLeftMove(e:MouseEvent):void{
var newY:Number;
newY = e.localY+e.currentTarget.y;
_iconLeft.visible = true;
_iconLeft.x = _bg.x;
if (newY > _bg.y+_HITZONE_FRAME_THICKNESS && newY < _bg.height+_bg.y-_HITZONE_FRAME_THICKNESS){
_iconLeft.y = newY;
}
}
private function _onLeftOut(e:MouseEvent):void{
_iconLeft.visible = false;
}
private function _onLeftUp(e:MouseEvent = null):void{
_mouseLeftMoveHandler();
_barLeft.x = _bg.x-(_HITZONE_FRAME_THICKNESS/2);
_barLeft.y = _bg.y+(_HITZONE_FRAME_THICKNESS);
_originalXBg = _bg.x;
_originalYBg = _bg.y;
_barTop.visible = true;
_barRight.visible = true;
_barBottom.visible = true; _topMoveBar.visible=true;
_cornerBottomLeft.visible = true;
_cornerBottomRight.visible = true;
_cornerTopLeft.visible = true;
_cornerTopRight.visible = true;
_barLeft.parent.removeEventListener(MouseEvent.MOUSE_MOVE, _mouseLeftMoveHandler);
_barLeft.parent.stage.removeEventListener(Event.MOUSE_LEAVE, _onLeftLeavesMovie);
_barLeft.stopDrag();
}
/*********************Bottom Left Corner HitZone***************************/
private function _onBottomLeftDown(e:MouseEvent):void{
_iconBottomLeft.x = _cornerBottomLeft.x;
_iconBottomLeft.y = _cornerBottomLeft.y;
_iconBottomLeft.visible = true;
_barBottom.visible = false; _topMoveBar.visible=false;
_barRight.visible = false;
_barTop.visible = false;
_barLeft.visible = false;
_cornerBottomRight.visible = false;
_cornerTopLeft.visible = false;
_cornerTopRight.visible = false;
_cornerBottomLeft.parent.addEventListener(MouseEvent.MOUSE_MOVE, _mouseBottomLeftMoveHandler);
_cornerBottomLeft.parent.stage.addEventListener(Event.MOUSE_LEAVE, _onBottomLeftLeavesMovie);
_cornerBottomLeft.startDrag();
}
private function _onBottomLeftUp(e:MouseEvent = null):void{
_mouseBottomLeftMoveHandler();
_cornerBottomLeft.y = _bg.y+_bg.height;
_cornerBottomLeft.x = _bg.x;
_barBottom.visible = true; _topMoveBar.visible=true;
_barRight.visible = true;
_barTop.visible = true;
_barLeft.visible = true;
_cornerBottomRight.visible = true;
_cornerTopLeft.visible = true;
_cornerTopRight.visible = true;
_cornerBottomLeft.parent.removeEventListener(MouseEvent.MOUSE_MOVE, _mouseBottomLeftMoveHandler);
_cornerBottomLeft.parent.stage.removeEventListener(Event.MOUSE_LEAVE, _onBottomLeftLeavesMovie);
_cornerBottomLeft.stopDrag();
}
private function _mouseBottomLeftMoveHandler(e:MouseEvent = null):void{
var newHeight:Number;
var newWidth:Number;
var distanceMovedOnX:Number;
var limitedCoords:Point;
//check to make sure this is not out of bounds
limitedCoords = _keepInBounds(_cornerBottomLeft.x,_cornerBottomLeft.y);
newHeight = limitedCoords.y-_bg.y;
if (newHeight > _minHeight ){
_bg.height = newHeight;
} else {
_bg.height = _minHeight;
}
_barBottom.y = _bg.height+_bg.y-(_HITZONE_FRAME_THICKNESS/2);
_iconBottomLeft.y = _bg.y+_bg.height;
distanceMovedOnX = (limitedCoords.x-_bg.x);
newWidth = _bg.width-distanceMovedOnX;
if (newWidth > _minWidth ){
_bg.width = newWidth;
_bg.x = _bg.x+distanceMovedOnX;
} else {
distanceMovedOnX = _bg.width-_minWidth;
_bg.width = _minWidth;
_bg.x = _bg.x+distanceMovedOnX;
}
_iconBottomLeft.x = _bg.x;
_iconTopLeft.x = _bg.x;
_cornerTopLeft.x = _bg.x;
_barLeft.x = _bg.x-(_HITZONE_FRAME_THICKNESS/2);
_barBottom.x = _bg.x+(_HITZONE_FRAME_THICKNESS);
_iconLeft.y = limitedCoords.y;
_barRight.graphics.clear();
_barRight.graphics.beginFill(0, _FRAME_ALPHA);
_barRight.graphics.drawRect(0, 0, _HITZONE_FRAME_THICKNESS, _bg.height-(2*_HITZONE_FRAME_THICKNESS));
_barRight.graphics.endFill();
_iconRight.x = limitedCoords.x;
_iconBottom.y = limitedCoords.y;
_barBottom.graphics.clear();
_barBottom.graphics.beginFill(0, _FRAME_ALPHA);
_barBottom.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS);
_barBottom.graphics.endFill();
_cornerBottomRight.y = _bg.y+_bg.height;
_cornerBottomRight.x = _bg.x+_bg.width;
_cornerTopRight.x = _bg.x+_bg.width;
_barLeft.graphics.clear();
_barLeft.graphics.beginFill(0, _FRAME_ALPHA);
_barLeft.graphics.drawRect(0, 0, _HITZONE_FRAME_THICKNESS, _bg.height-(2*_HITZONE_FRAME_THICKNESS));
_barLeft.graphics.endFill();
_barTop.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_barTop.y = _bg.y-(_HITZONE_FRAME_THICKNESS/2);
_iconTop.visible = false;
_iconTop.y = _barTop.y;
_barTop.graphics.clear();
_barTop.graphics.beginFill(0, _FRAME_ALPHA);
_barTop.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS);
_barTop.graphics.endFill();
_topMoveBar.y = _bg.y+(_HITZONE_FRAME_THICKNESS/2);
_topMoveBar.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_topMoveBar.graphics.clear();
_topMoveBar.graphics.beginFill(0, _FRAME_ALPHA);
_topMoveBar.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS*2);
_topMoveBar.graphics.endFill();
this.dispatchEvent( new UiEvent(UiEvent.RESIZE_WINDOW, {x:_bg.x+_this.x, y:_bg.y+_this.y, width:_bg.width*_this.scaleX, height:_bg.height*_this.scaleY}, false, true) );
if (e != null){
e.updateAfterEvent();
}
}
private function _onBottomLeftLeavesMovie(e:Event):void{
_onBottomLeftUp();
}
private function _onBottomLeftOver(e:MouseEvent):void{
_iconBottomLeft.x = _cornerBottomLeft.x;
_iconBottomLeft.y = _cornerBottomLeft.y;
_iconBottomLeft.visible = true;
}
private function _onBottomLeftOut(e:MouseEvent):void{
_iconBottomLeft.x = _cornerBottomLeft.x;
_iconBottomLeft.y = _cornerBottomLeft.y;
_iconBottomLeft.visible = false;
}
/*********************Top HitZone***************************/
private function _onTopDown(e:MouseEvent):void{
_iconTop.visible = true;
_iconTop.y = _barTop.y;
_barRight.visible = false;
_barBottom.visible = false; _topMoveBar.visible=false;
_barLeft.visible = false;
_cornerTopLeft.visible = false;
_cornerTopRight.visible = false;
_cornerBottomLeft.visible = false;
_cornerBottomRight.visible = false;
_barTop.parent.addEventListener(MouseEvent.MOUSE_MOVE, _mouseTopMoveHandler);
_barTop.parent.stage.addEventListener(Event.MOUSE_LEAVE, _onTopLeavesMovie);
_barTop.startDrag();
}
private function _onTopLeavesMovie(e:Event){
_onTopUp();
}
private function _mouseTopMoveHandler(e:MouseEvent = null):void {
var newHeight:Number;
var distanceMovedOnY:Number;
var limitedCoords:Point;
//check to make sure this is not out of bounds
limitedCoords = _keepInBounds(_barTop.x,_barTop.y);
distanceMovedOnY = (limitedCoords.y-_bg.y)+(_HITZONE_FRAME_THICKNESS/2);
newHeight = _bg.height-distanceMovedOnY;
if (newHeight > _minHeight ){
_bg.height = newHeight;
_bg.y = _bg.y+distanceMovedOnY;
} else {
distanceMovedOnY = _bg.height-_minHeight;
_bg.height = _minHeight;
_bg.y = _bg.y+distanceMovedOnY;
}
_iconTop.y = _bg.y;
_cornerTopRight.y = _iconTop.y;
_cornerTopLeft.y = _iconTop.y;
_barRight.y = _iconTop.y+_HITZONE_FRAME_THICKNESS;
_barLeft.y = _iconTop.y+_HITZONE_FRAME_THICKNESS;
_barRight.graphics.clear();
_barRight.graphics.beginFill(0, _FRAME_ALPHA);
_barRight.graphics.drawRect(0,0,_HITZONE_FRAME_THICKNESS,_bg.height-(2*_HITZONE_FRAME_THICKNESS));
_barRight.graphics.endFill();
_barLeft.graphics.clear();
_barLeft.graphics.beginFill(0, _FRAME_ALPHA);
_barLeft.graphics.drawRect(0, 0, _HITZONE_FRAME_THICKNESS, _bg.height-(2*_HITZONE_FRAME_THICKNESS));
_barLeft.graphics.endFill();
_topMoveBar.y = _bg.y+(_HITZONE_FRAME_THICKNESS/2);
_topMoveBar.x = _bg.x+_HITZONE_FRAME_THICKNESS;
this.dispatchEvent( new UiEvent(UiEvent.RESIZE_WINDOW, {x:_bg.x+_this.x, y:_bg.y+_this.y, width:_bg.width*_this.scaleX, height:_bg.height*_this.scaleY}, false, true) );
if (e != null){
e.updateAfterEvent();
}
}
private function _onTopMove(e:MouseEvent):void{
var newX:Number;
newX = e.localX+e.currentTarget.x;
if (newX > _bg.x+_HITZONE_FRAME_THICKNESS && newX < _bg.width+_bg.x-_HITZONE_FRAME_THICKNESS){
_iconTop.x = newX;
_iconTop.visible = true;
} else if (newX > _bg.width+_bg.x-_HITZONE_FRAME_THICKNESS) {
_iconTop.x = _bg.x+_bg.width-_HITZONE_FRAME_THICKNESS;
_iconTop.visible = true;
} else if (newX < _bg.x+_HITZONE_FRAME_THICKNESS){
_iconTop.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_iconTop.visible = true;
}
}
private function _onTopOut(e:MouseEvent):void{
_iconTop.visible = false;
}
private function _onTopUp(e:MouseEvent = null):void{
var newHeight:Number;
_iconTop.visible = false;
_mouseTopMoveHandler();
_barTop.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_barTop.y = _bg.y-(_HITZONE_FRAME_THICKNESS/2);
_iconTop.y = _barTop.y;
_cornerBottomRight.y = _bg.y+_bg.height;
_cornerBottomLeft.y = _bg.y+_bg.height;
_barRight.graphics.clear();
_barRight.graphics.beginFill(0, _FRAME_ALPHA);
_barRight.graphics.drawRect(0,0,_HITZONE_FRAME_THICKNESS,_bg.height-(2*_HITZONE_FRAME_THICKNESS));
_barRight.graphics.endFill();
_barLeft.graphics.clear();
_barLeft.graphics.beginFill(0, _FRAME_ALPHA);
_barLeft.graphics.drawRect(0, 0, _HITZONE_FRAME_THICKNESS, _bg.height-(2*_HITZONE_FRAME_THICKNESS));
_barLeft.graphics.endFill();
_barRight.visible = true;
_barBottom.visible = true; _topMoveBar.visible=true;
_barLeft.visible = true;
_cornerTopLeft.visible = true;
_cornerTopRight.visible = true;
_cornerBottomLeft.visible = true;
_cornerBottomRight.visible = true;
_barTop.parent.removeEventListener(MouseEvent.MOUSE_MOVE, _mouseTopMoveHandler);
_barTop.parent.stage.removeEventListener(Event.MOUSE_LEAVE, _onTopLeavesMovie);
_barTop.stopDrag();
_checkBounds();
}
/*********************Top Left Corner HitZone***************************/
private function _onTopLeftDown(e:MouseEvent):void{
_iconTopLeft.x = _cornerTopLeft.x;
_iconTopLeft.y = _cornerTopLeft.y;
_iconTopLeft.visible = true;
_barBottom.visible = false; _topMoveBar.visible=false;
_barRight.visible = false;
_barTop.visible = false;
_barLeft.visible = false;
_cornerBottomRight.visible = false;
_cornerBottomLeft.visible = false;
_cornerTopRight.visible = false;
_cornerTopLeft.parent.addEventListener(MouseEvent.MOUSE_MOVE, _mouseTopLeftMoveHandler);
_cornerTopLeft.parent.stage.addEventListener(Event.MOUSE_LEAVE, _onTopLeftLeavesMovie);
_cornerTopLeft.startDrag();
}
private function _onTopLeftUp(e:MouseEvent = null):void{
_mouseTopLeftMoveHandler();
_cornerTopLeft.y = _bg.y;
_cornerTopLeft.x = _bg.x;
_iconTopLeft.visible = false;
_barBottom.visible = true; _topMoveBar.visible=true;
_barRight.visible = true;
_barTop.visible = true;
_barLeft.visible = true;
_cornerBottomRight.visible = true;
_cornerBottomLeft.visible = true;
_cornerTopRight.visible = true;
_cornerTopLeft.parent.removeEventListener(MouseEvent.MOUSE_MOVE, _mouseTopLeftMoveHandler);
_cornerTopLeft.parent.stage.removeEventListener(Event.MOUSE_LEAVE, _onTopLeftLeavesMovie);
_cornerTopLeft.stopDrag();
_checkBounds();
}
private function _mouseTopLeftMoveHandler(e:MouseEvent = null):void{
var newHeight:Number;
var newWidth:Number;
var distanceMovedOnX:Number;
var distanceMovedOnY:Number;
var limitedCoords:Point;
//check to make sure this is not out of bounds
limitedCoords = _keepInBounds(_cornerTopLeft.x,_cornerTopLeft.y);
distanceMovedOnY = (limitedCoords.y-_bg.y);
newHeight = _bg.height-distanceMovedOnY;
if (newHeight > _minHeight ){
_bg.height = newHeight;
_bg.y = _bg.y+distanceMovedOnY;
} else {
distanceMovedOnY = _bg.height-_minHeight;
_bg.height = _minHeight;
_bg.y = _bg.y+distanceMovedOnY;
}
_barTop.y = _bg.height+_bg.y+(_HITZONE_FRAME_THICKNESS/2);
_iconTopLeft.y = _bg.y;
distanceMovedOnX = (limitedCoords.x-_bg.x);
newWidth = _bg.width-distanceMovedOnX;
if (newWidth > _minWidth ){
_bg.width = newWidth;
_bg.x = _bg.x+distanceMovedOnX;
} else {
distanceMovedOnX = _bg.width-_minWidth;
_bg.width = _minWidth;
_bg.x = _bg.x+distanceMovedOnX;
}
_iconTopLeft.x = _bg.x;
_iconBottomLeft.x = _bg.x;
_cornerBottomLeft.x = _bg.x;
_barLeft.x = _bg.x-(_HITZONE_FRAME_THICKNESS/2);
_barLeft.y = _bg.y+(_HITZONE_FRAME_THICKNESS);
_barRight.y = _bg.y+(_HITZONE_FRAME_THICKNESS);
_barBottom.x = _bg.x+(_HITZONE_FRAME_THICKNESS);
_iconLeft.y = _cornerTopLeft.y;
_barRight.graphics.clear();
_barRight.graphics.beginFill(0, _FRAME_ALPHA);
_barRight.graphics.drawRect(0, 0, _HITZONE_FRAME_THICKNESS, _bg.height-(2*_HITZONE_FRAME_THICKNESS));
_barRight.graphics.endFill();
_iconRight.x = limitedCoords.x;
_iconBottom.y = limitedCoords.y;
_barBottom.graphics.clear();
_barBottom.graphics.beginFill(0, _FRAME_ALPHA);
_barBottom.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS);
_barBottom.graphics.endFill();
_cornerBottomRight.y = _bg.y+_bg.height;
_cornerBottomRight.x = _bg.x+_bg.width;
_cornerTopRight.x = _bg.x+_bg.width;
_cornerTopRight.y = _bg.y;
_barLeft.graphics.clear();
_barLeft.graphics.beginFill(0, _FRAME_ALPHA);
_barLeft.graphics.drawRect(0, 0, _HITZONE_FRAME_THICKNESS, _bg.height-(2*_HITZONE_FRAME_THICKNESS));
_barLeft.graphics.endFill();
_barTop.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_barTop.y = _bg.y-(_HITZONE_FRAME_THICKNESS/2);
_iconTop.visible = false;
_iconTop.y = _barTop.y;
_barTop.graphics.clear();
_barTop.graphics.beginFill(0, _FRAME_ALPHA);
_barTop.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS);
_barTop.graphics.endFill();
_topMoveBar.y = _bg.y+(_HITZONE_FRAME_THICKNESS/2);
_topMoveBar.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_topMoveBar.graphics.clear();
_topMoveBar.graphics.beginFill(0, _FRAME_ALPHA);
_topMoveBar.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS*2);
_topMoveBar.graphics.endFill();
this.dispatchEvent( new UiEvent(UiEvent.RESIZE_WINDOW, {x:_bg.x+_this.x, y:_bg.y+_this.y, width:_bg.width*_this.scaleX, height:_bg.height*_this.scaleY}, false, true) );
if (e != null){
e.updateAfterEvent();
}
}
private function _onTopLeftLeavesMovie(e:Event):void{
_onTopLeftUp();
}
private function _onTopLeftOver(e:MouseEvent):void{
_iconTopLeft.x = _cornerTopLeft.x;
_iconTopLeft.y = _cornerTopLeft.y;
_iconTopLeft.visible = true;
}
private function _onTopLeftOut(e:MouseEvent):void{
_iconTopLeft.x = _cornerTopLeft.x;
_iconTopLeft.y = _cornerTopLeft.y;
_iconTopLeft.visible = false;
}
/*********************Top Right Corner HitZone***************************/
private function _onTopRightDown(e:MouseEvent):void{
_iconTopRight.x = _cornerTopRight.x;
_iconTopRight.y = _cornerTopRight.y;
_barBottom.visible = false; _topMoveBar.visible=false;
_barRight.visible = false;
_barTop.visible = false;
_barLeft.visible = false;
_cornerBottomLeft.visible = false;
_cornerTopLeft.visible = false;
_cornerBottomRight.visible = false;
_cornerTopRight.parent.addEventListener(MouseEvent.MOUSE_MOVE, _mouseTopRightMoveHandler);
_cornerTopRight.parent.stage.addEventListener(Event.MOUSE_LEAVE, _onTopRightLeavesMovie);
_cornerTopRight.startDrag();
}
private function _onTopRightUp(e:MouseEvent = null):void{
_mouseTopRightMoveHandler();
_iconRight.x = _cornerTopRight.x;
_iconTop.y = _cornerTopRight.y;
_cornerTopRight.y = _bg.y;
_cornerTopRight.x = _bg.x+_bg.width;
_barBottom.y = _bg.y+_bg.height-(_HITZONE_FRAME_THICKNESS/2);
_cornerBottomRight.y = _bg.y+_bg.height;
_cornerBottomLeft.y = _bg.y+_bg.height;
_barBottom.visible = true; _topMoveBar.visible=true;
_barRight.visible = true;
_barTop.visible = true;
_barLeft.visible = true;
_cornerBottomLeft.visible = true;
_cornerTopLeft.visible = true;
_cornerBottomRight.visible = true;
_cornerTopRight.parent.removeEventListener(MouseEvent.MOUSE_MOVE, _mouseTopRightMoveHandler);
_cornerTopRight.parent.stage.removeEventListener(Event.MOUSE_LEAVE, _onTopRightLeavesMovie);
_cornerTopRight.stopDrag();
_checkBounds();
}
private function _mouseTopRightMoveHandler(e:MouseEvent = null):void{
var newHeight:Number;
var newWidth:Number;
var distanceMovedOnX:Number;
var distanceMovedOnY:Number;
var limitedCoords:Point;
//check to make sure this is not out of bounds
limitedCoords = _keepInBounds(_cornerTopRight.x,_cornerTopRight.y);
distanceMovedOnY = limitedCoords.y-_bg.y;
newHeight = _bg.height-distanceMovedOnY;
if (newHeight > _minHeight ){
_bg.height = newHeight;
_bg.y = limitedCoords.y;
} else {
_bg.y = _bg.y-(_bg.height-_minHeight);
_bg.height = _minHeight;
}
_barTop.y = _bg.y-(_HITZONE_FRAME_THICKNESS/2);
newWidth = limitedCoords.x-_bg.x;
if (newWidth > _minWidth ){
_bg.width = newWidth;
} else {
_bg.width = _minWidth;
}
_barRight.y = _bg.y+_HITZONE_FRAME_THICKNESS;
_barRight.x = _bg.width+_bg.x-(_HITZONE_FRAME_THICKNESS/2);
_iconRight.y = _bg.y;
_barRight.graphics.clear();
_barRight.graphics.beginFill(0, _FRAME_ALPHA);
_barRight.graphics.drawRect(0, 0, _HITZONE_FRAME_THICKNESS, _bg.height-(2*_HITZONE_FRAME_THICKNESS));
_barRight.graphics.endFill();
_iconRight.x = _bg.x+_bg.width;
_iconTop.y = _bg.y;
_barBottom.graphics.clear();
_barBottom.graphics.beginFill(0, _FRAME_ALPHA);
_barBottom.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS);
_barBottom.graphics.endFill();
_barTop.graphics.clear();
_barTop.graphics.beginFill(0, _FRAME_ALPHA);
_barTop.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS);
_barTop.graphics.endFill();
_iconTopRight.x = _bg.width+_bg.x;
_iconTopRight.y = _bg.y;
_cornerTopLeft.y = _bg.y;
_cornerBottomRight.x = _bg.x+_bg.width;
_barLeft.y = _bg.y+_HITZONE_FRAME_THICKNESS;
_barLeft.graphics.clear();
_barLeft.graphics.beginFill(0, _FRAME_ALPHA);
_barLeft.graphics.drawRect(0, 0, _HITZONE_FRAME_THICKNESS, _bg.height-(2*_HITZONE_FRAME_THICKNESS));
_barLeft.graphics.endFill();
_topMoveBar.y = _bg.y+(_HITZONE_FRAME_THICKNESS/2);
_topMoveBar.x = _bg.x+_HITZONE_FRAME_THICKNESS;
_topMoveBar.graphics.clear();
_topMoveBar.graphics.beginFill(0, _FRAME_ALPHA);
_topMoveBar.graphics.drawRect(0, 0, _bg.width-(2*_HITZONE_FRAME_THICKNESS), _HITZONE_FRAME_THICKNESS*2);
_topMoveBar.graphics.endFill();
this.dispatchEvent( new UiEvent(UiEvent.RESIZE_WINDOW, {x:_bg.x+_this.x, y:_bg.y+_this.y, width:_bg.width*_this.scaleX, height:_bg.height*_this.scaleY}, false, true) );
if (e != null){
e.updateAfterEvent();
}
}
private function _onTopRightLeavesMovie(e:Event):void{
_onTopRightUp();
}
private function _onTopRightOver(e:MouseEvent):void{
_iconTopRight.x = _cornerTopRight.x;
_iconTopRight.y = _cornerTopRight.y;
_iconTopRight.visible = true;
}
private function _onTopRightOut(e:MouseEvent):void{
_iconTopRight.x = _cornerTopRight.x;
_iconTopRight.y = _cornerTopRight.y;
_iconTopRight.visible = false;
}
////////////top drag bar/////////////
private function _onTopMoveDown(e:MouseEvent):void{
_topMoveBar.parent.addEventListener(MouseEvent.MOUSE_MOVE, _mouseTopMoveBarMoveHandler);
_topMoveBar.parent.stage.addEventListener(Event.MOUSE_LEAVE, _onTopMoveLeavesMovie);
_this.startDrag();
}
private function _onTopMoveUp(e:MouseEvent = null):void{
_mouseTopMoveBarMoveHandler();
_topMoveBar.parent.removeEventListener(MouseEvent.MOUSE_MOVE, _mouseTopMoveBarMoveHandler);
_topMoveBar.parent.stage.removeEventListener(Event.MOUSE_LEAVE, _onTopMoveLeavesMovie);
_this.stopDrag();
_checkBounds();
}
private function _mouseTopMoveBarMoveHandler(e:MouseEvent = null):void {
//TODO: when you move we can,t move the whole movie, we have to move all its components
this.dispatchEvent( new UiEvent(UiEvent.RESIZE_WINDOW, {x:_bg.x+_this.x, y:_bg.y+_this.y, width:_bg.width*_this.scaleX, height:_bg.height*_this.scaleY}, false, true) );
if (e != null){
e.updateAfterEvent();
}
}
private function _onTopMoveLeavesMovie(e:Event):void{
_onTopMoveUp();
}
private function _keepInBounds(x:Number,y:Number):Point{
var globalCoords:Point = _bg.parent.localToGlobal(new Point(x,y));
var localCoords:Point = new Point(x,y);
var globalOrigin:Point = new Point( (_nativeWindowSizeWidth-_bg.root.stage.stageWidth)/2 , (_nativeWindowSizeHeight-_bg.root.stage.stageHeight)/2 );
var globalOuterLimits:Point = new Point( _bg.root.stage.stageWidth+globalOrigin.x , _bg.root.stage.stageHeight+globalOrigin.y );
var localLimited:Point;
var finalX:Number = x;
var finalY:Number = y;
if (_nativeWindowSizeWidth == -1 || _nativeWindowSizeHeight == -1){
//dont limit snap back
return new Point(finalX, finalY);
}
if ( globalCoords.x < globalOrigin.x ) {
localLimited = _this.globalToLocal(globalOrigin);
finalX = localLimited.x;
} else if (globalCoords.x > globalOuterLimits.x){
localLimited = _this.globalToLocal(globalOuterLimits);
finalX = localLimited.x;
}
if ( globalCoords.y < globalOrigin.y ) {
localLimited = _this.globalToLocal(globalOrigin);
finalY = localLimited.y;
} else if (globalCoords.y > globalOuterLimits.y){
localLimited = _this.globalToLocal(globalOuterLimits);
finalY = localLimited.y;
}
return new Point(finalX, finalY);
}
private function _checkBounds():void{
if (_nativeWindowSizeWidth == -1 || _nativeWindowSizeHeight == -1){
//dont limit snap back
trace("set not to limit drag area");
return;
}
var rectangle:Rectangle = _topMoveBar.getBounds(_bg.root);
//var rectangle2:Rectangle = _bg.root.getBounds(_bg.root.stage);
var globalLowerRightCoords:Point = rectangle.bottomRight;
var localLowerRightCoords:Point;
var localTopLeftCoords:Point;
var newOriginTransform:Point = new Point( (_nativeWindowSizeWidth-_bg.root.stage.stageWidth)/2 , (_nativeWindowSizeHeight-_bg.root.stage.stageHeight)/2 );
var globalOuterLimits:Point = new Point( _bg.root.stage.stageWidth+newOriginTransform.x , _bg.root.stage.stageHeight+newOriginTransform.y );
var newLocalOrigin:Point;
var isSnappedBack:Boolean;
if (globalLowerRightCoords.x < (20+newOriginTransform.x) ) {
localLowerRightCoords = _this.parent.globalToLocal(globalLowerRightCoords);
localTopLeftCoords = _this.parent.globalToLocal(new Point(rectangle.x,rectangle.y));
newLocalOrigin = _this.parent.globalToLocal(newOriginTransform);
_this.x = newLocalOrigin.x-(localLowerRightCoords.x-localTopLeftCoords.x)+20;
isSnappedBack = true;
} else if (rectangle.x > globalOuterLimits.x-20){
localTopLeftCoords = _this.parent.globalToLocal(globalOuterLimits);
_this.x = localTopLeftCoords.x-20;
isSnappedBack = true;
}
if (globalLowerRightCoords.y < (20+newOriginTransform.y) ) {
localLowerRightCoords = _this.parent.globalToLocal(globalLowerRightCoords);
localTopLeftCoords = _this.parent.globalToLocal(new Point(rectangle.x,rectangle.y));
newLocalOrigin = _this.parent.globalToLocal(newOriginTransform);
_this.y = newLocalOrigin.y-(localLowerRightCoords.y-localTopLeftCoords.y)+30;
isSnappedBack = true;
} else if (rectangle.y > globalOuterLimits.y-20){
localTopLeftCoords = _this.parent.globalToLocal(globalOuterLimits);
_this.y = localTopLeftCoords.y-30;
isSnappedBack = true;
}
if (isSnappedBack){
this.dispatchEvent( new UiEvent(UiEvent.RESIZE_WINDOW, {x:_bg.x+_this.x, y:_bg.y+_this.y, width:_bg.width*_this.scaleX, height:_bg.height*_this.scaleY}, false, true) );
}
}
//TODO: make resize work inside of browser, use fire bug to see when _nativeWindowSizeHeight and stageWidth are being updated
//TODO: double click and it minimizes to a bar
//sometimes when you drag it off stage it does not snap back, add a timed event after you drop it to double check
//TODO: spiff up the arrow icons to have windows or mac icons depending on what system they are using.
//TODO: add function to turn resize off and to bind it to the stage size
//TODO: destroy method
}
}
view raw ResizeWindow.as hosted with ❤ by GitHub
package com.actionscriptflashguru{
import flash.events.EventDispatcher;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.DisplayObject;
import flash.display.MovieClip;
public class UiEvent extends Event{
public static const CLOSE:String = "closesubui";
public static const RESIZE_WINDOW:String = "resizewindow";
public var params:Object;
public function UiEvent(type:String, params:Object, bubbles:Boolean = false, cancelable:Boolean = false) {
super(type, bubbles, cancelable);
this.params = params;
}
public override function clone():Event{
return new UiEvent(type, this.params, bubbles, cancelable);
}
public override function toString():String{
return formatToString("UiEvent", "params", "type", "bubbles", "cancelable");
}
}
}
view raw UiEvent.as hosted with ❤ by GitHub