//------------------------------------------------------------------------------ // // COPYRIGHT © 2008 NEONDUST STUDIOS. ALL RIGHTS RESERVED. // //------------------------------------------------------------------------------ package com.neondust.external { import flash.external.ExternalInterface; import flash.net.URLRequest; import flash.net.navigateToURL; /** */ public class PopupWindow { //---------------------------------------------------------------------- // // PUBLIC CONSTANTS // //---------------------------------------------------------------------- /** * The name of the JavaScript function that will be used to open * the popup window. The function should have the following signature: * * openPopupWindow( uri, name, opts ) */ public static const OPEN_WINDOW_FUNCTION:String = "openPopupWindow"; //---------------------------------------------------------------------- // // PUBLIC PROPERTIES // //---------------------------------------------------------------------- /** * The x position of the popup window, in pixels. If this value is * less than 0 the x position of the popup is set by the browser. * * @default -1 */ public var x:int = PopupWindowDefaults.x; /** * The y position of the popup window, in pixels. If this value is * less than 0 the y position of the popup is set by the browser. * * @default -1 */ public var y:int = PopupWindowDefaults.y; /** * The width of the popup window, in pixels. If this value is * less than 0 the width of the popup is set by the browser. * * @default -1 */ public var width:int = PopupWindowDefaults.width; /** * The height of the popup window, in pixels. If this value is * less than 0 the height of the popup is set by the browser. * * @default -1 */ public var height:int = PopupWindowDefaults.height; /** * Indicates if the popup window menu bar should be displayed. * * @default false */ public var menuBar:Boolean = PopupWindowDefaults.menuBar; /** * Indicates if the popup window tool bar should be displayed. * * @default false */ public var toolBar:Boolean = PopupWindowDefaults.toolBar; /** * Indicates if the popup window location bar should be displayed. * * @default false */ public var locationBar:Boolean = PopupWindowDefaults.locationBar; /** * Indicates if the popup window status bar should be displayed. * * @default false */ public var statusBar:Boolean = PopupWindowDefaults.statusBar; /** * Indicates if the popup window scroll bars should be displayed. * * @default false */ public var scrollBars:Boolean = PopupWindowDefaults.scrollBars; /** * Indicates if the popup window should be resizable. * * @default false */ public var resizable:Boolean = PopupWindowDefaults.resizable; //---------------------------------------------------------------------- // // PRIVATE PROPERTIES // //---------------------------------------------------------------------- /** * @private */ private static var nextID:uint = 0; /** * @private */ private var _uri:String = ""; /** * @private */ private var _name:String = ""; //---------------------------------------------------------------------- // // CONSTRUCTOR // //---------------------------------------------------------------------- /** */ public function PopupWindow() { _name = "popupwindow_" + ( nextID ++ ); } //---------------------------------------------------------------------- // // PUBLIC METHODS // //---------------------------------------------------------------------- /** * Attempts to open a new popup window. * * @param uri * The URI of the page or file to load into the popup window. */ public function open( uri:String ):void { _uri = uri; var result:Boolean = false; if( ExternalInterface.available ) { var func:String = OPEN_WINDOW_FUNCTION; var opts:String = optionsToString(); result = ExternalInterface.call( func, uri, name, opts ) as Boolean; } if( result == false ) { navigate(); } } //---------------------------------------------------------------------- // // PRIVATE METHODS // //---------------------------------------------------------------------- /** * @private */ private function navigate():void { var request:URLRequest = new URLRequest( uri ); navigateToURL( request, "_blank" ); } /** * @private */ private function optionsToString():String { var opts:Array = []; if( x > -1 ) { opts.push( "left=" + x ); } if( y > -1 ) { opts.push( "top=" + y ); } if( width > -1 ) { opts.push( "width=" + width ); opts.push( "innerWidth=" + width ); } if( height > -1 ) { opts.push( "height=" + height ); opts.push( "innerHeight=" + height ); } opts.push( "menubar=" + ( menuBar ? "yes" : "no" ) ); opts.push( "toolbar=" + ( toolBar ? "yes" : "no" ) ); opts.push( "location=" + ( locationBar ? "yes" : "no" ) ); opts.push( "status=" + ( statusBar ? "yes" : "no" ) ); opts.push( "scrollbars=" + ( scrollBars ? "yes" : "no" ) ); opts.push( "resizable=" + ( resizable ? "yes" : "no" ) ); return opts.join( "," ); } //---------------------------------------------------------------------- // // GETTERS/SETTERS // //---------------------------------------------------------------------- /** * The URI that was passed to the open() method. This value will be * an empty string until the open() method is first invoked. */ public function get uri():String // read-only { return _uri; } /** * The name of the popup window. This value is set internally by the * PopupWindow class. */ public function get name():String // read-only { return _name; } } }