header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
rani
Points:310
Posts:10
Answered

2/2/2010 7:33:40 AM

Title: maximize and minimise titlewindow


how to make a titlewindow that looks and works like a window with minimise and maximise and restore button?



Alex
Points: 0
Posts:0
Accepted Answer
2/2/2010 11:17:36 AM



I have a code sample to create a minimise and maximise effect. Here is the code
Create a class file with name flexScript.as and paste code

package

{
	import flash.events.MouseEvent;
	
	import mx.containers.Panel;
	import mx.controls.Button;
	import mx.effects.Resize;
	
	public class flexScript extends Panel
	{
		private var minMaxBtn:Button = new Button();
		private var effResize:Resize = new Resize();
		private var previousHeight:int = 30;
		
		public function flexScript()
		{
			super();
			minMaxBtn.addEventListener(MouseEvent.CLICK, minimisePanel);
		}
		
		override protected function createChildren():void{
			super.createChildren();
			super.titleBar.addChild(minMaxBtn);
		}
		
		private function minimisePanel(e:MouseEvent):void{
			effResize.stop();
			minMaxBtn.removeEventListener(MouseEvent.CLICK, minimisePanel);
			minMaxBtn.addEventListener(MouseEvent.CLICK, maxmisePanel);
			effResize.heightFrom = height;
			effResize.heightTo = previousHeight;
			previousHeight = height;
			effResize.play([this]);
		}
		
		private function maxmisePanel(e:MouseEvent):void{
			effResize.stop();
			minMaxBtn.removeEventListener(MouseEvent.CLICK, maxmisePanel);
			minMaxBtn.addEventListener(MouseEvent.CLICK, minimisePanel);
			effResize.heightFrom = height;
			effResize.heightTo = previousHeight;
			previousHeight = height;
			effResize.play([this]);
		}
		
		override protected function updateDisplayList(w:Number, h:Number):void{
			super.updateDisplayList(w,h);
			minMaxBtn.x = super.titleBar.width - 30;
			minMaxBtn.y = 5;
			minMaxBtn.width = 20;
			minMaxBtn.height = 20;
		}
		
	}
}

use it in mxml file 


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="1024" minHeight="768" xmlns:ns1="*">
	<ns1:flexScript x="90" y="52" width="342" height="235">
	</ns1:flexScript>
</mx:Application>

rani
Points: 0
Posts:0
2/3/2010 12:35:39 AM



hi Alex
how to use this class for dynamic display.
thanks in advance

rani
Points: 0
Posts:0
2/5/2010 12:07:25 AM



i m using this code for maximizing and minimise a panel in side a titlewindow,how i can write the code to maximisi and minimise titlewindow itself in an application.

First i created a component titlewindow as:


<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" 
layout="absolute" 
width="100%" height="100%" showCloseButton="true"> 
<mx:Script> 
<![CDATA[ 
import mx.core.UIComponent; 
import mx.managers.SystemManager; 
import mx.controls.Alert; 
import mx.collections.ArrayCollection; 
import mx.managers.PopUpManager; 
import mx.containers.TitleWindow; 
import mx.core.IFlexDisplayObject; 
import mx.containers.Panel; 


// Button constants 
private static const _RESTORE_LABEL_:String = "Min"; 
private static const _MAXIMIZE_LABEL_:String = "Max"; 


[Bindable] 
private var currWidth:int; // Stores the current width of the panel to be resized 

[Bindable] 
private var currHeight:int; // Stores the current height of the panel to be resized 

[Bindable] 
private var currTop:int; // Stores the current y coordinate of the panel to be resized 

[Bindable] 
private var currLeft:int; // Stores the current x coordinate of the panel to be resized 

[Bindable] 
private var isMaximized:Boolean = false; // Stores the current state of the panel as a boolean
 
[Bindable] 
private var currIndex:int; // Stores the current index of the panel to be maximized 



/** 
* This function orchestrates what method 
* is called on the button click event depending on 
* its label value. 
*/ 
private function maxRestore(thePanel:Panel, minRestorBtn:Button):void 
{ 
if(minRestorBtn.label == _RESTORE_LABEL_) 
restore(thePanel, minRestorBtn); 
else if(minRestorBtn.label == _MAXIMIZE_LABEL_) 
maximize(thePanel, minRestorBtn); 



} 


/** 
* This method maximizes the specified panel to occupy the 
* whole displayed screen area. This method can be tuned to 
* occupy the area of its parent component rather than the parent 
* application. 
*/ 
private function maximize(thePanel:Panel, minRestorBtn:Button):void 
{ 
if(!isMaximized) 
{ 
// Save previous position info 
currWidth = thePanel.width; 
currHeight = thePanel.height; 
currTop = thePanel.y; 
currLeft = thePanel.x; 
currIndex = thePanel.parent.getChildIndex(thePanel);// 
this.getChildIndex(thePanel) ; 

// Set the maximized flag to true 
isMaximized = true; 


// Set current info 
thePanel.width=this.width; 
thePanel.height = this.height; 
thePanel.x = 0; 
thePanel.y = 0; 


var parentApp:UIComponent = thePanel.parent as UIComponent// 
this as UIComponent; 
parentApp.removeChildAt(currIndex); 
parentApp.addChild(thePanel); 


// Set the button properties 
minRestorBtn.label = _RESTORE_LABEL_; 



} 
} 


/** 
* This method restores the panel to its original location 
* and size on the screen. 
*/ 
private function restore(thePanel:Panel,minRestorBtn:Button):void 
{ 
if(isMaximized) 
{ 
var parentApp:UIComponent = thePanel.parent as UIComponent;// 
this as UIComponent; 
// Set the maximized flag to false 
isMaximized = false; 

// Set the button properties 
minRestorBtn.label = _MAXIMIZE_LABEL_; 


// Restore the original size and location information 
thePanel.width = currWidth; 
thePanel.height = currHeight; 
thePanel.x = currLeft; 
thePanel.y = currTop; 


// Now relocate the panel to its original position 
// in the child stack. 
parentApp.setChildIndex(thePanel,currIndex); 
} 
} 
]]> 
</mx:Script> 
<mx:Resize id="resize" /> <!-- This helps in the resize effect --> 
<mx:Move id="moveEffect" /> <!-- This helps in the move effect --> 
<mx:Panel id="upperPanel" x="47.5" y="35" width="50%" height="20%" 
layout="absolute" 
resizeEffect="{resize}" 
moveEffect="{moveEffect}" backgroundAlpha="1.0" 
borderAlpha="1.0" title="Top Panel"> 
<mx:Button id="upperPanelMaxBtn" label="{_MAXIMIZE_LABEL_}" 
click="maxRestore(upperPanel, upperPanelMaxBtn)"/> 
</mx:Panel> 
<!-- This panel has the capability to maximize and restore --> 
</mx:TitleWindow>


then in main application i call titlewindow as

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication   xmlns:mx="http://www.adobe.com/2006/mxml" 
layout="absolute" 
width="100%" height="100%" xmlns:components="components.*" xmlns:local="*"> 
<local:comp/>
</mx:WindowedApplication>

HELP PLEASE

David
Points: 0
Posts:0
2/5/2010 6:18:59 AM



hi rani I am also looking for a similar code, do you want the window to minimize to footer on clicking the minimise button ? I tried your code and the one posted by Alex.

The code form alex is working for me it created a button the header right side and when I press it,my window is minimised. Further I moved the window to left-bottom of the application.


rani
Points: 0
Posts:0
2/7/2010 9:55:08 PM



hi David
please tell me how to move window to left-bottom of the application

rani
Points: 0
Posts:0
2/7/2010 9:55:23 PM



hi David
please tell me how to move window to left-bottom of the application
thanks in advance


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 8+6 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions