*
+ * Copyright 2007 Christopher Olsen *
+ * *
+ * $Id$ *
+ ************************************************************************/
+
+package {
+ import flash.net.Socket;
+ import flash.events.IOErrorEvent;
+ import mx.controls.Alert;
+ import flash.events.ProgressEvent;
+ import flash.events.Event;
+ import flash.utils.ByteArray;
+ import flash.utils.Timer;
+ import flash.events.TimerEvent;
+ import mx.collections.ArrayCollection;
+ import mx.utils.ArrayUtil;
+
+ public class tuveNetwork {
+ private var tvSocket:Socket;
+ public var tvMaster:Master;
+ private var attempts:Number = 0;
+ private var myTimer:Timer = new Timer(20000,1);
+ public var tvNetCon:Boolean = false;
+ private var curTime:Number;
+
+ public function init():void {
+ myTimer.addEventListener(TimerEvent.TIMER_COMPLETE,conSocketEvent);
+ conSocketEvent(null);
+ } /* End init() */
+
+ private function conSocketEvent(event:TimerEvent):void {
+ if (attempts >=3) {
+ Alert.show("Cannot reconnect to server. Some services will not be available.");
+ }
+ else {
+ if (tvSocket == null)
+ this.tvSocket = new Socket();
+ this.tvSocket.addEventListener(IOErrorEvent.IO_ERROR,onConnectError,false,0,true);
+ this.tvSocket.addEventListener(ProgressEvent.SOCKET_DATA,gotData,false,0,true);
+ this.tvSocket.addEventListener(Event.CONNECT,doNetAuth,false,0,true);
+ this.tvSocket.addEventListener(Event.CLOSE,doReconnect,false,0,true);
+ tvSocket.connect("tuved.ubixonline.com",9999);
+ attempts++;
+ }
+ }
+
+ /* Send data to the socket */
+ public function sendData(data:String):void {
+ tvSocket.writeUTFBytes(data);
+ tvSocket.flush();
+ } /* End sendData */
+
+ /* Let's auth to the network */
+ private function doNetAuth(event:Event):void {
+ tvNetCon = true;
+ tvSocket.writeUTFBytes("ident " + tvMaster.userName + ":" + tvMaster.tvSO.data.myID + "\n");
+ tvSocket.flush();
+ } /* End doNetAuth */
+
+ private function doNetSuccess():void {
+ tvMaster.userList = null;
+ tvMaster.userList = new XMLList();
+ tvMaster.masterObject.userDispList.dataProvider = tvMaster.userList;
+
+ tvSocket.writeUTFBytes("join " + tvMaster.currentChannel + "\n");
+ tvSocket.flush();
+ attempts = 0;
+
+ tvMaster.masterObject.chatWindow.htmlText += "CONNECTED To Server.
";
+
+ if ((tvMaster.myQueue != null) && (tvMaster.myQueue.length > 0)) {
+ tvSocket.writeUTFBytes("QUEUE FULL\n");
+ tvSocket.flush();
+ }
+ }
+
+ private function onConnectError(event:IOErrorEvent):void {
+ if (event.text.match("close"))
+ myTimer.start();
+ else
+ Alert.show("ERROR: " + event.text);
+ } /* End onConnectionError */
+
+ private function gotData(event:ProgressEvent):void {
+ var _data:String;
+ var _dataArray:Array;
+ var data:String;
+ var dataArray:Array;
+ var _i:Number;
+ var i:Number;
+ var x:Number;
+ var tmpString:String;
+ var fc:Boolean = false;
+ var date:Date;
+
+ event.bytesLoaded
+
+ _data = this.tvSocket.readUTFBytes(this.tvSocket.bytesAvailable);
+ _dataArray = _data.split("\n");
+
+ for (_i = 0;_dataArray[_i] != null;_i++) {
+ data = _dataArray[_i];
+
+ if (data.length <= 0)
+ return;
+
+
+ if (data.indexOf("MSG") == 0) {
+ dataArray = data.split(":");
+ tmpString = dataArray[3];
+ for (i=4;dataArray[i] != null;i++)
+ tmpString += ":" + dataArray[i];
+
+ if (dataArray[2].match("PRIVMSG")) {
+ tvMaster.sendIM(dataArray[1],tmpString);
+ }
+ else {
+ date = new Date;
+ if (dataArray[1].match("TUveD")) {
+ tvMaster.masterObject.chatWindow.htmlText += "[" + date.toLocaleTimeString() + "] " + dataArray[1] + ": " + tmpString + "
";
+ }
+ else {
+ tvMaster.masterObject.chatWindow.htmlText += "[" + date.toLocaleTimeString() + "] " + dataArray[1] + ": " + tmpString + "
";
+ }
+ }
+ }
+ else if (data.indexOf("EMOTE") == 0) {
+ dataArray = data.split(":");
+ tmpString = dataArray[3];
+ for (i=4;dataArray[i] != null;i++)
+ tmpString += ":" + dataArray[i];
+ date = new Date;
+ tvMaster.masterObject.chatWindow.htmlText += "[" + date.toLocaleTimeString() + "] " + dataArray[1] + " " + tmpString + "\n";
+ }
+ else if (data.indexOf("PING") == 0) {
+ tvSocket.writeUTFBytes("PONG!\n");
+ tvSocket.flush();
+ }
+ else if (data.indexOf("LIST") == 0) {
+ dataArray = data.split(":");
+ tvMaster.tuveShowLW();
+
+ if (dataArray[1].match("Channel")) {
+ tvMaster.channels = null;
+ tvMaster.channels = new XMLList();
+ }
+ else {
+ tvMaster.channels += new XML("");
+ }
+
+ }
+ else if (data.indexOf("JOIN") == 0) {
+ dataArray = data.split(":");
+ i = 2;
+ while (dataArray[i] != null) {
+ if (dataArray[i].indexOf("&") == 0)
+ tmpString = dataArray[i].toString().substring(1,dataArray[i].toString().length);
+ else
+ tmpString = dataArray[i];
+
+ tvMaster.userList += new XML("");
+ if (tvMaster.userName.match(dataArray[i])) {
+ tvMaster.topicHistory = null;
+ tvMaster.topicHistory = new XMLList();
+ tvMaster.masterObject.chatWindow.htmlText += "You Are Now Talking In: " + dataArray[1] + "\n";
+ tvMaster.currentChannel = dataArray[1];
+ //Alert.show(tvMaster.chanList.length());
+ for (x = 0;x < tvMaster.chanList.length();x++) {
+ //Alert.show(tvMaster.chanList[x].@data);
+ if (tvMaster.currentChannel.match(tvMaster.chanList[x].@data)) {
+ tvMaster.masterObject.selChan.selectedIndex = x;
+ fc = true;
+ }
+ }
+ if (fc == false) {
+ tvMaster.chanList += new XML("");
+ tvMaster.masterObject.selChan.selectedIndex = tvMaster.chanList.length() - 1;
+ }
+ }
+ i += 2;
+ }
+ }
+ else if (data.indexOf("GETVIDEO") == 0) {
+ if (tvMaster.myQueue != null && tvMaster.myQueue.length > 0) {
+ tvSocket.writeUTFBytes("VIDEO " + tvMaster.currentChannel + ":" + tvMaster.myQueue[0].vid + "\n");
+ tvMaster.myQueue.removeItemAt(0);
+ tvSocket.flush();
+ }
+ else {
+ tvSocket.writeUTFBytes("QUEUE EMPTY\n");
+ tvSocket.flush();
+ }
+ }
+ else if (data.indexOf("PAUSE") == 0) {
+ curTime = tvMaster.tvNS.time;
+ tvMaster.myTimer.stop();
+ tvMaster.tvNS.close();
+ }
+ else if (data.indexOf("RESUME") == 0) {
+ tvMaster.tvNS.play(tvMaster.curSong,curTime);
+ tvMaster.myTimer.start();
+ }
+ else if (data.indexOf("SEEK") == 0) {
+ dataArray = data.split(":");
+ if (dataArray[1] != null)
+ tvMaster.tvNS.seek(Number(dataArray[1]));
+ }
+ else if (data.indexOf("CURPOS") == 0) {
+ dataArray = data.split(":");
+ tvMaster.tvGotMeta = false;
+ tvMaster.curSong = dataArray[2];
+ if (tvMaster.tvNC.connected == false) {
+ Alert.show("ERROR: tvMaster.tvNC.connected == false");
+ return;
+ }
+ tvMaster.tvNS.close();
+ tvMaster.myTimer.stop();
+ tvMaster.myTimer.reset();
+ tvMaster.tvStartTime = Number(dataArray[1]);
+ tvMaster.myTimer.delay = 1000;
+ tvMaster.myCount = Number(dataArray[4]) - tvMaster.tvStartTime;
+ tvMaster.myTimer.repeatCount = tvMaster.myCount;
+ tvMaster.myTimer.start();
+ if (tvMaster.curSong.indexOf("stream") == 0) {
+ tvMaster.tvNS.play(tvMaster.curSong,-1);
+ tvMaster.tvVid.width = 320;
+ tvMaster.tvVid.height = 240;
+ tvMaster.tvVid.y = 30;
+ tvMaster.tvVid.x = 40;
+
+ }
+ else
+ tvMaster.tvNS.play(tvMaster.curSong,0);
+
+ tvMaster.masterObject.songTitle.text = dataArray[3];
+ tvMaster.vid = Number(dataArray[5]);
+ tvMaster.getInfo();
+
+ }
+ else if (data.indexOf("BAN") == 0) {
+ if (tvMaster.tuveFW == null) {
+ tvMaster.tuveFW = new formatWindow();
+ tvMaster.masterObject.addChild(tvMaster.tuveFW);
+ tvMaster.tuveFW.tvMaster = tvMaster;
+ tvMaster.tuveFW.addEventListener("closeWindow",tvMaster.tuveCloseFW,false,0,true);
+ }
+ }
+ else if (data.indexOf("KICK") == 0) {
+ dataArray = data.split(":");
+ tmpString = dataArray[3];
+ for (i=4;dataArray[i] != null;i++)
+ tmpString += ":" + dataArray[i];
+ tvMaster.masterObject.chatWindow.htmlText += "You Have Been Kick By: " + dataArray[2] + " For " + tmpString + "\n";
+ tvMaster.userList = null;
+ tvMaster.userList = new XMLList;
+ }
+ else if (data.indexOf("PART") == 0) {
+ dataArray = data.split(":");
+
+ for (i=0;i");
+ tvMaster.masterObject.userDispList.dataProvider = tvMaster.userList;
+ break;
+ }
+ }
+ } /* End NICK */
+ else if (data.indexOf("MODE") == 0) {
+ dataArray = data.split(":");
+ switch (dataArray[2]) {
+ case 'E':
+ if (dataArray[3] == '1')
+ tvMaster.masterObject.tvE.selected = true;
+ else
+ tvMaster.masterObject.tvE.selected = false;
+ break;
+ case 'R':
+ if (dataArray[3] == '1')
+ tvMaster.masterObject.tvR.selected = true;
+ else
+ tvMaster.masterObject.tvR.selected = false;
+ break;
+ case 'Q':
+ if (dataArray[3] == '1')
+ tvMaster.masterObject.tvQ.selected = true;
+ else
+ tvMaster.masterObject.tvQ.selected = false;
+ break;
+ case 'T':
+ if (dataArray[3] == '1')
+ tvMaster.masterObject.tvT.selected = true;
+ else
+ tvMaster.masterObject.tvT.selected = false;
+ tvMaster.masterObject.tvTime.text = dataArray[4];
+ break;
+ case 'A':
+ for (i = 0;i");
+ tvMaster.masterObject.userDispList.dataProvider = tvMaster.userList;
+ break;
+ }
+ }
+ break;
+ }
+ }
+ else if (data.indexOf("IDENT") == 0) {
+ dataArray = data.split(":");
+ if (dataArray[1] == 0) {
+ doNetSuccess();
+ tvMaster.authSuccess();
+ }
+ else {
+ tvMaster.masterObject.authFail(dataArray[2]);
+ }
+ }
+ else if (data.indexOf("TOPIC") == 0) {
+ var topic:Object = new Object();
+ dataArray = data.split(":");
+ tmpString = dataArray[2];
+ for (i=3;dataArray[i] != null;i++)
+ tmpString += ":" + dataArray[i];
+
+ for (i=0;i");
+ tvMaster.masterObject.topicNew.selectedIndex = tvMaster.topicHistory.length() - 1;
+ }
+
+ } /*End big for */
+ }
+
+ /* Reconnect when connection fails */
+ private function doReconnect(event:Event):void {
+ tvMaster.masterObject.chatWindow.htmlText += "DISCONNECTED From Server!!!
";
+ tvNetCon = false;
+ myTimer.start(); /* Reconnect */
+ } /* End doReconnect() */
+
+ } /* End podzNEtwork Class */
+
+ } /* End package */
\ No newline at end of file
diff --git a/src/tvWindow.as b/src/tvWindow.as
new file mode 100644
index 0000000..9a6c267
--- /dev/null
+++ b/src/tvWindow.as
@@ -0,0 +1,489 @@
+/****************************************************************
+ * ucWindow Class, by Christopher Olsen
+ * Copyright 2007 Christopher Olsen
+ *
+ * This is the PodWindow container
+ *
+ * It handles the following:
+ * Window Resize
+ * Invokes Windows Close Event
+ *
+ * It contains the following:
+ * Top margin for window move
+ * Left margine for window move
+ * Minimum window size
+ * Max window size
+ * !! Note: The pod manager can override these values
+ *
+ * $Id$
+ ***************************************************************/
+
+package {
+
+ import flash.events.MouseEvent;
+ import flash.events.Event;
+ import mx.controls.Button;
+ import mx.containers.Panel;
+ import mx.controls.Image;
+ import mx.events.FlexEvent
+ import flash.geom.Point;
+ import mx.managers.CursorManager;
+ import mx.managers.CursorManagerPriority;
+ import mx.core.Application;
+ import mx.containers.ApplicationControlBar;
+ import mx.controls.ColorPicker;
+ import mx.events.ColorPickerEvent;
+ import mx.events.DragEvent;
+ import mx.core.DragSource;
+ import mx.managers.DragManager;
+
+ public class tvWindow extends Panel {
+
+ /* Mouse Pointers */
+ [Embed(source="assets/leftObliqueSize.gif")]
+ private static var leftObliqueSize:Class;
+ [Embed(source="assets/rightObliqueSize.gif")]
+ private static var rightObliqueSize:Class;
+ [Embed(source="assets/horizontalSize.gif")]
+ private static var horizontalSize:Class;
+ [Embed(source="assets/verticalSize.gif")]
+ private static var verticalSize:Class;
+
+ /* The close button */
+ private var closeButton:Button;
+ [Embed(source="assets/closeButtonUp.gif")]
+ private var closeButtonUp:Class;
+ [Embed(source="assets/closeButtonOver.gif")]
+ private var closeButtonOver:Class;
+ [Embed(source="assets/closeButtonDown.gif")]
+ private var closeButtonDown:Class;
+ /* The min button */
+ private var minButton:Button;
+ [Embed(source="assets/minButtonUp.gif")]
+ private var minButtonUp:Class;
+ [Embed(source="assets/minButtonOver.gif")]
+ private var minButtonOver:Class;
+ [Embed(source="assets/minButtonDown.gif")]
+ private var minButtonDown:Class;
+
+ /* The max button */
+ private var maxButton:Button;
+ [Embed(source="assets/maxButtonUp.gif")]
+ private var maxButtonUp:Class;
+ [Embed(source="assets/maxButtonOver.gif")]
+ private var maxButtonOver:Class;
+ [Embed(source="assets/maxButtonDown.gif")]
+ private var maxButtonDown:Class;
+ [Embed(source="assets/restButtonUp.gif")]
+ private var restButtonUp:Class;
+ [Embed(source="assets/restButtonOver.gif")]
+ private var restButtonOver:Class;
+ [Embed(source="assets/restButtonDown.gif")]
+ private var restButtonDown:Class;
+
+ private var mMC:Boolean = false;
+
+ private var _pwMin:Boolean = false;
+ private var _stageY: Number;
+ private var _startY: Number;
+ private var _startX: Number;
+ private var _dragStartX: Number;
+ private var _dragStartY: Number;
+ private var oWidth:Number;
+ private var oHeight:Number;
+ //public var myPod:Podz;
+ public var closeable:Boolean = true;
+ private var resizePoint:Point = new Point();
+ private var resizeType:Number = 0;
+ public var tvSizable:Boolean = true;
+
+ /* Previous x,y width and height before maximized */
+ private var oldX:Number = 0;
+ private var oldY:Number = 0;
+ private var oldWidth:Number = 0;
+ private var oldHeight:Number = 0;
+ private var pwButtonVisible:Boolean = false;
+ private var pwAttached:Boolean = false;
+
+
+ public function tvWindow() {
+ super();
+ this.addEventListener(FlexEvent.CREATION_COMPLETE, pwInit);
+ this.addEventListener(MouseEvent.MOUSE_DOWN, mouseClickHandler, false);
+ this.addEventListener(MouseEvent.MOUSE_MOVE, oMouseMove, false);
+ this.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler,true);
+ this.setStyle("borderThicknessTop",0);
+ this.setStyle("borderThicknessBottom",0);
+ this.setStyle("borderThicknessLeft",0);
+ this.setStyle("borderThicknessRight",0);
+ this.setStyle("headerHeight",20);
+ this.setStyle("borderAlpha",.75);
+ this.setStyle("borderColor","#808080");
+ } /* end Pod Window */
+
+ /******************************************************
+ * Handlers Section
+ *
+ ******************************************************/
+ private function pwMouseOver(event:MouseEvent):void {
+ pwShowButtons();
+ }
+
+ private function pwMouseOut(event:MouseEvent):void {
+ pwHideButtons();
+ }
+
+ private function pwInit(event:FlexEvent):void {
+ titleBar.addEventListener(MouseEvent.MOUSE_OVER, pwMouseOver,false,0,true);
+ titleBar.addEventListener(MouseEvent.MOUSE_OUT, pwMouseOut,false,0,true);
+ }
+
+ /*
+ This function attaches the buttons to the PodWindow
+ */
+
+ public function pwAttachButtons():void {
+ var nC:Boolean = false;
+
+ /*
+ if (myPod != null)
+ nC = myPod.podzMaster.podzManager.nC;
+ */
+
+ if ((closeButton == null) && (nC == false)) {
+ closeButton = new Button();
+ closeButton.width=10;
+ closeButton.height=10;
+ closeButton.focusEnabled=false;
+ closeButton.setStyle("upSkin", closeButtonUp);
+ closeButton.setStyle("overSkin", closeButtonOver);
+ closeButton.setStyle("downSkin", closeButtonDown);
+ closeButton.addEventListener(MouseEvent.CLICK, closeButtonHandler);
+ titleBar.addChild(closeButton);
+ }
+ else if ((closeButton != null) && (closeable == false)) {
+ titleBar.removeChild(closeButton);
+ closeButton.removeEventListener(MouseEvent.CLICK,closeButtonHandler);
+ closeButton = null;
+ }
+
+ if ((maxButton == null) && (tvSizable == true)) {
+ maxButton = new Button();
+ maxButton.width=10;
+ maxButton.height=10;
+ maxButton.focusEnabled=false;
+ maxButton.setStyle("upSkin", maxButtonUp);
+ maxButton.setStyle("overSkin", maxButtonOver);
+ maxButton.setStyle("downSkin", maxButtonDown);
+ maxButton.addEventListener(MouseEvent.CLICK, maxButtonHandler);
+ titleBar.addChild(maxButton);
+ }
+
+ if ((minButton == null) && (tvSizable == true)) {
+ minButton = new Button();
+ minButton.width=10;
+ minButton.height=10;
+ minButton.focusEnabled=false;
+ minButton.setStyle("upSkin", minButtonUp);
+ minButton.setStyle("overSkin", minButtonOver);
+ minButton.setStyle("downSkin", minButtonDown);
+ minButton.addEventListener(MouseEvent.CLICK, minButtonHandler);
+ titleBar.addChild(minButton);
+ }
+
+ pwAttached = true;
+ alignButtons();
+ } /* end addButtons */
+
+
+ // Event handler for mouse over moves
+ private function oMouseMove(event:MouseEvent):void {
+ var contentPoint:Point = event.currentTarget.globalToContent(new Point(event.stageX, event.stageY));
+
+ if (_pwMin == true)
+ return;
+
+ if ((contentPoint.y > event.currentTarget.height - 40) && (contentPoint.x > event.currentTarget.width - 30)){
+ CursorManager.removeCursor(CursorManager.currentCursorID);
+ CursorManager.setCursor(leftObliqueSize,CursorManagerPriority.MEDIUM, -6, -6);
+ mMC = true;
+ }
+ else if ((contentPoint.y < -15) && (contentPoint.x > event.currentTarget.width - 5)) {
+ CursorManager.removeCursor(CursorManager.currentCursorID);
+ CursorManager.setCursor(rightObliqueSize,CursorManagerPriority.MEDIUM, -6, -6);
+ mMC = true;
+ }
+ else if (mMC == true) {
+ CursorManager.removeCursor(CursorManager.currentCursorID);
+ mMC = false;
+ }
+ } /* End oMouseMose */
+
+ // Event handler to do actual resize
+ private function pwDoResize(event:MouseEvent):void {
+ var xPlus:Number = Application.application.parent.mouseX - resizePoint.x;
+ var yPlus:Number = Application.application.parent.mouseY - resizePoint.y;
+ var newY:Number;
+
+ switch (resizeType) {
+ case 1:
+ this.width = oWidth + xPlus > 0 ? oWidth + xPlus : this.width;
+ this.height = oHeight + yPlus > 0 ? oHeight + yPlus : this.height;
+ break;
+ case 2:
+ this.width = oWidth + xPlus > 0 ? oWidth + xPlus : this.width;
+
+ newY = _startY + event.stageY - _stageY;
+ if (newY >= 1) {
+ this.y = newY;
+ this.height = oHeight - yPlus > 0 ? oHeight - yPlus : this.height;
+ }
+
+ break;
+ }
+ /* re-align the buttons */
+ alignButtons();
+ }
+
+ // Event handler to end resize
+ private function pwEndResize(event:MouseEvent):void {
+ var xPlus:Number = Application.application.parent.mouseX - resizePoint.x;
+ var yPlus:Number = Application.application.parent.mouseY - resizePoint.y;
+ var newY:Number;
+
+ event.stopImmediatePropagation();
+
+ Application.application.parent.removeEventListener(MouseEvent.MOUSE_MOVE, pwDoResize, true);
+ Application.application.parent.removeEventListener(MouseEvent.MOUSE_UP, pwEndResize, true);
+
+ switch (resizeType) {
+ case 1:
+ this.width = oWidth + xPlus > 0 ? oWidth + xPlus : this.width;
+ this.height = oHeight + yPlus > 0 ? oHeight + yPlus : this.height;
+ break;
+ case 2:
+ this.width = oWidth + xPlus > 0 ? oWidth + xPlus : this.width;
+
+ newY = _startY + event.stageY - _stageY;
+ if (newY >= 1) {
+ this.y = newY;
+ this.height = oHeight - yPlus > 0 ? oHeight - yPlus : this.height;
+ }
+
+ break;
+ }
+ /* re-align the buttons */
+ alignButtons();
+
+ /* Unset resizeType incase event is still in propagation */
+ resizeType = 0;
+
+ } /* End pwEndResize */
+
+ private function mouseOutHandler(event:MouseEvent):void {
+ CursorManager.removeCursor(CursorManager.currentCursorID);
+ }
+
+ // Event handler for mouse click
+ private function mouseClickHandler(event:MouseEvent):void {
+ var contentPoint:Point = event.currentTarget.globalToContent(new Point(event.stageX, event.stageY));
+ //podParent.setChildIndex(event.currentTarget,podParent.numChildren-1);
+ this.parentDocument.setChildIndex(event.currentTarget,this.parentDocument.numChildren-1);
+
+ if ((contentPoint.y > this.height - 40) && (contentPoint.x > this.width - 30) && (tvSizable == true)){
+ _dragStartX = event.localX;
+ _dragStartY = event.localY;
+
+ oWidth = event.currentTarget.width;
+ oHeight = event.currentTarget.height;
+
+ resizePoint = event.currentTarget.localToGlobal(new Point(event.currentTarget.mouseX,event.currentTarget.mouseY));
+
+ resizeType = 1;
+
+ Application.application.parent.addEventListener(MouseEvent.MOUSE_UP, pwEndResize, true);
+ Application.application.parent.addEventListener(MouseEvent.MOUSE_MOVE, pwDoResize, true);
+ }
+ else if ((contentPoint.y < -15) && (contentPoint.x > this.width - 5) && (tvSizable == true)) {
+ _dragStartX = event.localX;
+ _dragStartY = event.localY;
+
+ _startY = event.currentTarget.y;
+ _stageY = event.stageY;
+
+ oWidth = event.currentTarget.width
+ oHeight = event.currentTarget.height;
+ resizePoint = event.currentTarget.localToGlobal(new Point(event.currentTarget.mouseX,event.currentTarget.mouseY));
+ resizeType = 2;
+ Application.application.parent.addEventListener(MouseEvent.MOUSE_UP, pwEndResize, true);
+ Application.application.parent.addEventListener(MouseEvent.MOUSE_MOVE, pwDoResize, true);
+ }
+ else if ((contentPoint.y < 0) && (contentPoint.x < (event.currentTarget.width - 5))) {
+ Application.application.parent.addEventListener(MouseEvent.MOUSE_UP, podEndMove, true);
+ Application.application.parent.addEventListener(MouseEvent.MOUSE_MOVE, podDoMove, true);
+ _startX = event.currentTarget.x;
+ _startY = event.currentTarget.y;
+ _dragStartX = event.stageX;
+ _dragStartY = event.stageY;
+ }
+
+
+ } /* End hMouseClick */
+
+ public function closeButtonHandler(event:MouseEvent):void{
+ dispatchEvent(new FlexEvent("closeWindow"));
+ } /* end buttonCloseHandler */
+
+ private function minButtonHandler(event:MouseEvent):void {
+ this.oldHeight = this.height;
+ this.oldWidth = this.width;
+ this.oldY = this.y;
+
+ this.height = this.titleBar.height;
+
+ maxButton.setStyle("upSkin", restButtonUp);
+ maxButton.setStyle("overSkin", restButtonOver);
+ maxButton.setStyle("downSkin", restButtonDown);
+
+ _pwMin = true;
+
+ } /* End minButtonHandler() */
+
+ private function maxButtonHandler(event:MouseEvent):void {
+ if (this.oldY != 0) {
+ if (_pwMin != true) {
+ this.x = this.oldX;
+ this.y = this.oldY;
+ }
+ else
+ _pwMin = false;
+
+ this.height = this.oldHeight;
+ this.width = this.oldWidth;
+ this.oldY = 0;
+ maxButton.setStyle("upSkin", maxButtonUp);
+ maxButton.setStyle("overSkin", maxButtonOver);
+ maxButton.setStyle("downSkin", maxButtonDown);
+ }
+ else {
+ this.oldX = this.x;
+ this.oldY = this.y;
+ this.oldHeight = this.height;
+ this.oldWidth = this.width;
+ this.width = this.parentDocument.width - 2;
+ this.height = this.parentDocument.height - 23;
+ this.y = 1;
+ this.x = 1;
+ maxButton.setStyle("upSkin", restButtonUp);
+ maxButton.setStyle("overSkin", restButtonOver);
+ maxButton.setStyle("downSkin", restButtonDown);
+ }
+
+ resizeType = 0;
+
+ this.titleBar.width = this.width;
+ alignButtons();
+ } /* End maxButtonHandler() */
+
+ /******************************************************
+ * Private functions to the new container class
+ *
+ *****************************************************/
+ public function pwHideButtons():void {
+
+ if (closeButton != null)
+ closeButton.visible = false;
+
+ if (maxButton != null)
+ maxButton.visible = false;
+
+ if (minButton != null)
+ minButton.visible = false;
+
+ pwButtonVisible = false;
+ }
+
+ public function pwShowButtons():void {
+ if (pwAttached == false)
+ pwAttachButtons();
+
+ if (closeButton != null)
+ closeButton.visible = true;
+
+ if (maxButton != null)
+ maxButton.visible = true;
+
+ if (minButton != null)
+ minButton.visible = true;
+
+ pwButtonVisible = true;
+ }
+
+ private function alignButtons():void {
+ var bcnt:Number = 1;
+
+ if (closeButton != null) {
+ closeButton.move(titleBar.width - (bcnt * 16), (titleBar.height - 10) / 2);
+ bcnt++;
+ }
+ if (maxButton != null) {
+ maxButton.move(titleBar.width - (bcnt * 16), (titleBar.height - 10) / 2);
+ bcnt++;
+ }
+ if (minButton != null) {
+ minButton.move(titleBar.width - (bcnt * 16), (titleBar.height - 10) / 2);
+ bcnt++;
+ }
+
+
+ if (pwButtonVisible == true)
+ pwShowButtons();
+ else
+ pwHideButtons();
+ }
+
+ /*************/
+ private function podDoMove(event:MouseEvent):void {
+ var newY:Number;
+ var newX:Number;
+ event.stopImmediatePropagation();
+
+ newY = _startY + event.stageY - _dragStartY;
+ newX = _startX + event.stageX - _dragStartX;
+
+ if (newY > 1 && newX > 1)
+ move(newX,newY);
+ else if (newY > 1 && newX < 1)
+ move(1,newY);
+ else if (newY < 1 && newX < 1)
+ move(1,1);
+ else
+ move(newX,1);
+ } /* End podDoMove */
+
+ // Event handler to end moving
+ private function podEndMove(event:MouseEvent):void {
+ var newY:Number;
+ var newX:Number;
+
+ event.stopImmediatePropagation();
+ Application.application.parent.removeEventListener(MouseEvent.MOUSE_MOVE, podDoMove, true);
+ Application.application.parent.removeEventListener(MouseEvent.MOUSE_UP, podEndMove, true);
+
+ newY = _startY + event.stageY - _dragStartY;
+ newX = _startX + event.stageX - _dragStartX;
+
+ if (newY > 22 && newX > 1)
+ move(newX,newY);
+ else if (newY > 1 && newX < 1)
+ move(1,newY);
+ else if (newY < 1 && newX < 1)
+ move(1,1);
+ else
+ move(newX,1);
+ } /* End podEndMove */
+ /*************/
+
+ } /* end class */
+
+ } /* end package */
\ No newline at end of file