package
{
	import com.distriqt.extension.nativewebview.NativeWebView;
	import com.distriqt.extension.nativewebview.NativeWebViewOptions;
	import com.distriqt.extension.nativewebview.events.BrowserViewEvent;
	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	
	public class TestBrowserView extends Sprite
	{
		

		public function TestBrowserView()
		{
			super();
			
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			stage.addEventListener( MouseEvent.CLICK, mouseClickHandler, false, 0, true );
			
			
			try
			{
				trace( "NativeWebView Supported: " + NativeWebView.isSupported );
				
				if (NativeWebView.isSupported)
				{
					trace( "NativeWebView Version:   " + NativeWebView.service.version );
					
					var options:NativeWebViewOptions = new NativeWebViewOptions();
					
					NativeWebView.service.initialisePlatform( options, function(success:Boolean):void
					{
						trace( "NativeWebView initialised: " + success );
						
						trace( "NativeWebView browserView.isSupported: " + NativeWebView.service.browserView.isSupported );
						
						if (NativeWebView.service.browserView.isSupported)
						{
							NativeWebView.service.browserView.addEventListener( BrowserViewEvent.READY, browserViewReadyHandler );
							NativeWebView.service.browserView.prepare();
						}
					});
				}
				
			}
			catch (e:Error)
			{
				trace( "ERROR::"+e.message );
			}
			
		}
		
		
		
		private function mouseClickHandler( event:MouseEvent ):void
		{
			if (NativeWebView.service.browserView.isSupported)
			{
				NativeWebView.service.browserView.openWithUrl( "https://airnativeextensions.com/resources/tests/nativewebview-browserview.html" );
			}
		}
		
		
		
		private function browserViewReadyHandler( event:BrowserViewEvent ):void
		{
			trace( "browserViewReadyHandler" );
		}
		
		
		
	}
}

