Skip to content

Instantly share code, notes, and snippets.

@kelegorm
Last active August 29, 2015 13:56
Show Gist options
  • Save kelegorm/9046433 to your computer and use it in GitHub Desktop.
Save kelegorm/9046433 to your computer and use it in GitHub Desktop.
<?xml version="1.0"?>
<!--
Created with IntelliJ IDEA.
User: kelegorm
Date: 25.03.13
Time: 11:17
-->
<s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
close="closeHandler(event)"
skinClass="skins.MyWindowSkin"
keyDown="keyDown2Handler(event)"
mouseDownOutside="mouseDownOutsideHandler(event)"
>
<s:layout>
<s:VerticalLayout paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10" gap="10" />
</s:layout>
<fx:Metadata>
[Event(name='buttonClick', type="view.windows.MyWindowEvent")]
[Event(name='cancelClick', type="view.windows.MyWindowEvent")]
</fx:Metadata>
<fx:Script><![CDATA[
import mx.events.CloseEvent;
import mx.events.FlexMouseEvent;
import mx.managers.PopUpManager;
import view.components.MyButton;
[Bindable]
public var buttonLabel:String = "";
[Bindable]
public var buttonHelp:String = "";
[SkinPart(required=true)]
public var okButton:MyButton;
[SkinPart(required=true)]
public var cancelButton:MyButton;
public var hideByOutsideClick:Boolean = false;
[Bindable]
public var showButtons:Boolean = true;
public function close():void {
dispatchEvent(new CloseEvent(CloseEvent.CLOSE));
}
protected function keyDown2Handler(event:KeyboardEvent):void {
if (event.keyCode == 27) {
dispatchEvent(new CloseEvent(CloseEvent.CLOSE));
}
}
override protected function partAdded(partName:String, instance:Object):void {
super.partAdded(partName, instance);
switch (instance) {
case okButton:
okButton.addEventListener(MouseEvent.CLICK, button_clickHandler);
break;
case cancelButton:
cancelButton.addEventListener(MouseEvent.CLICK, cancelButton_clickHandler);
break;
}
}
private function button_clickHandler(event:MouseEvent):void {
dispatchEvent(new MyWindowEvent(MyWindowEvent.BUTTON_CLICK));
}
private function cancelButton_clickHandler(event:MouseEvent):void {
dispatchEvent(new MyWindowEvent(MyWindowEvent.CANCEL_CLICK));
dispatchEvent(new CloseEvent(CloseEvent.CLOSE));
}
protected function closeHandler(event:CloseEvent):void {
PopUpManager.removePopUp(this);
focusManager.deactivate();
}
private function mouseDownOutsideHandler(event:FlexMouseEvent):void {
if (hideByOutsideClick) {
dispatchEvent(new CloseEvent(CloseEvent.CLOSE));
}
}
]]>
</fx:Script>
</s:TitleWindow>
/**
* Created with IntelliJ IDEA.
* User: kelegorm
* Date: 30.04.13
* Time: 23:34
*/
package view.windows {
import flash.events.Event;
public class MyWindowEvent extends Event {
public static const BUTTON_CLICK:String = 'buttonClick';
public static const CANCEL_CLICK:String = 'cancelClick';
public function MyWindowEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false) {
super(type, bubbles, cancelable);
}
}
}
//button click handler
var window:MyFineWindow = new MyFineWindow();
PopUpManager.addPopUp(window, FlexGlobals.topLevelApplication as DisplayObject, true);
PopUpManager.centerPopUp(window);
<?xml version="1.0"?>
<!-- MyFineWindow.mxml -->
<windows:MyWindow xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:windows="view.windows.*" xmlns:components="view.components.*" xmlns:layouts="spark.layouts.*"
showButtons="false"
hideByOutsideClick="true"
minHeight="150"
minWidth="230"
>
<windows:layout>
<layouts:BasicLayout />
</windows:layout>
<s:Label test="MyFineWindow!"/>
</windows:MyWindow>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment