Tip 2, Unregular Window, JWindow+GraphicsAsset

July 14th, 2008

Some times, our art designer prefer a unregular window, especially for a game UI or some cool application.

Well, here is a tip:


package{

import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.DropShadowFilter;
import flash.geom.Rectangle;

import org.aswing.*;
import org.aswing.border.EmptyBorder;

public class UnregularWindow extends Sprite{

[Embed(source="windowbg.png")]
private var imgClass:Class;

private var window:JWindow;

public function UnregularWindow(){
super();

AsWingManager.initAsStandard(this);

window = new JWindow();
var img:DisplayObject = new imgClass() as DisplayObject;
img.filters = [new DropShadowFilter()];
//make some blank space leave to the img shadow
window.setBorder(new EmptyBorder(null, new Insets(0, 0, 4, 4)));
window.setBackgroundDecorator(new AssetBackground(img));
//or even you can directly call addChild to append a image
//window.addChild(img);

var buttonPane:JPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
buttonPane.appendAll(new JButton("OK"), new JButton("Cancel"));
window.getContentPane().append(buttonPane, BorderLayout.SOUTH);
window.getContentPane().append(new JLabel("This is a JWindow"), BorderLayout.CENTER);
window.setSizeWH(300, 300);
window.show();
//simplly make the window dragable
window.addEventListener(MouseEvent.MOUSE_DOWN, __mouseDown);
window.addEventListener(MouseEvent.MOUSE_UP, __mouseUp);
}

private function __mouseDown(e:Event):void{
window.startDrag(false, new Rectangle(0, 0, stage.stageWidth, stage.stageHeight));
}

private function __mouseUp(e:Event):void{
window.stopDrag();
}
}
}

unregular window
(Click here to run the swf)
It is simple, just add a Image to the background of the JWindow, we added a Picture in this demo, but you, you even can add a Movie to be the background. Or even a MovieClip with Shapes, Buttons created by Flash IDE…

3 Responses to “Tip 2, Unregular Window, JWindow+GraphicsAsset”

  1. bernieon 23 Dec 2008 at 6:38 am

    What is “var imgClass:Class” in this sample?
    May I have the source code to compile, thx

  2. iileyon 23 Dec 2008 at 8:59 pm

    You know [Embed] sytanx in AS3?

  3. bernieon 25 Dec 2008 at 10:42 am

    iiley,
    I got it. thx for your hint.

Trackback URI | Comments RSS

Leave a Reply