Here I share some code of how to create a custom actionscript popup. The example below is a popup with an image in. When you click outside the popup it’ll close.
You create a popup like this:
import myPackage.ImagePopup;
import mx.core.IFlexDisplayObject;
import mx.managers.PopUpManager;
var _imagePopup:ImagePopup = new ImagePopup("image.jpg");
PopUpManager.addPopUp(_imagePopup,this.parentApplication as DisplayObject, true);
Here is the ImagePopup class:
package myPackage
{
import flash.events.Event;
import mx.controls.Image;
import mx.events.FlexMouseEvent;
import mx.managers.PopUpManager;
import mx.core.IFlexDisplayObject;
import spark.components.TitleWindow;
public class ImagePopup extends TitleWindow
{
private var _image:Image;
public function ImagePopup(src:String)
{
super();
title = "Title Here";
x=y=5;
width=402;
height=433;
this.addEventListener(Event.CLOSE,closePopup);
_image = new Image();
_image.x = 0; _image.y = 0; _image.width = 400; _image.height = 400;
_image.source = src;
addElement(_image);
this.addEventListener(FlexMouseEvent.MOUSE_DOWN_OUTSIDE, closePopup);
}
private function closePopup(e:Event):void
{
PopUpManager.removePopUp(this as IFlexDisplayObject);
}
}
}