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?
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>
2/3/2010 12:35:39 AM
hi Alex
how to use this class for dynamic display.
thanks in advance
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
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.
2/7/2010 9:55:08 PM
hi David
please tell me how to move window to left-bottom of the application
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