Tag Archives: neondust studios popupwindow

getting past IE popup blocker ActionScript3

can use this fix to bypass popups in IE…


/*

use this snippet in the as file to work with this class
 function  discoverBtnHandler(e:MouseEvent){

var popup:PassPopup = new PassPopup();
 // Open the popup window.
 popup.ChangePage( “http://blog.flashbanneronline.com/” );
 }

*/

package com {
 import flash.external.ExternalInterface;
 import flash.net.*;

public class PassPopup {
 public function ChangePage(url:*, window:String = “_blank”):void {
 var req:URLRequest = url is String ? new URLRequest(url) : url;
 if (!ExternalInterface.available) {
 navigateToURL(req, window);
 } else {
 var strUserAgent:String =  String(ExternalInterface.call(”function() {return  navigator.userAgent;}”)).toLowerCase();
 if (strUserAgent.indexOf(”firefox”) != -1 ||  (strUserAgent.indexOf(”msie”) != -1 &&  uint(strUserAgent.substr(strUserAgent.indexOf(”msie”) + 5, 3)) >= 7))  {
 ExternalInterface.call(”window.open”, req.url, window);
 } else {
 navigateToURL(req, window);
 }
 }
 }

}

}

and to use :


import com.neondust.external.PopupWindow;
 import com.neondust.external.PopupWindowDefaults;

var popup:PopupWindow = new PopupWindow();
 popup.width = WIDTH OF POPUP;
 popup.height = HEIGHT OF POPUP;
 popup.menuBar = false;
 popup.toolBar = false;
 popup.open( “YOUR HTML PAGE PATH” );

PopupWindow.as

//------------------------------------------------------------------------------
//
// 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;
		}

	}
}

PopupWindowDefaults.as

//------------------------------------------------------------------------------
//
// COPYRIGHT © 2008 NEONDUST STUDIOS. ALL RIGHTS RESERVED.
//
//------------------------------------------------------------------------------
package com.neondust.external
{
	/**
	 */
	public final class PopupWindowDefaults
	{
		//----------------------------------------------------------------------
		//
		// PUBLIC PROPERTIES
		//
		//----------------------------------------------------------------------

		/**
		 */
		public static var x:int = -1;

		/**
		 */
		public static var y:int = -1;

		/**
		 */
		public static var width:int = -1;

		/**
		 */
		public static var height:int = -1;

		/**
		 */
		public static var menuBar:Boolean = false;

		/**
		 */
		public static var toolBar:Boolean = false;

		/**
		 */
		public static var locationBar:Boolean = false;

		/**
		 */
		public static var statusBar:Boolean = false;

		/**
		 */
		public static var scrollBars:Boolean = false;

		/**
		 */
		public static var resizable:Boolean = false;

	}
}

//------------------------------------------------------------------------------
//
// 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;
		}

	}
}