Swiffy is a google project that allow Flash Pro (cs4+) to export his content (including Action Script !) to html.Yep a google project… not Adobe.

In order to melt your ‘flashtml’ app into the DOM, you may need to send and receive stuff frome the page.
Unfortunatly ExtenalInterface is not available when exported with Swiffy and I hope it will come in the next release.
Fortunatly there is a way to do it without modifying swiffy runtime > DEMO

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

update 05/10/2013

tested with runtime.js v5.2 & v5.3 release note

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Flash => Html

Just call the JS function with a NavigateToURL instead of the externalInterface.call method.

package 
{

	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.navigateToURL;
	import flash.net.URLRequest;

	public class Main extends MovieClip
	{

		public var enter_btn:SimpleButton;
		public var square_mc:MovieClip;

		public function Main()
		{
			this.addEventListener(Event.ADDED_TO_STAGE, _onAddedToStage );
		}


		private function _onAddedToStage(event:Event):void
		{
			enter_btn.addEventListener(MouseEvent.CLICK, _onClickEnter );
			this.addEventListener(Event.ENTER_FRAME, _oef );
		}
		
		private function _oef(e:Event):void
		{
			if(this.loaderInfo.parameters.call)
			{
				this[this.loaderInfo.parameters.call]();
				delete this.loaderInfo.parameters.call;
			}
		}

		private function _onClickEnter(e:MouseEvent=null):void
		{
			square_mc.gotoAndPlay(2);
		}		
		
		public function animationEnd():void
		{
			navigateToURL( new URLRequest( "javascript:lol();" ) ,'_self' );
		}
	}

}

in this code sample the javascript function ‘lol’ is called

Html => Flash

The only thing that swiffy expose to the outside is the setFlashVars method, the cool thing is that the flashvars can change at runtime, so you can catch them and build a bridge.

package 
{

	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.navigateToURL;
	import flash.net.URLRequest;

	public class Main extends MovieClip
	{

		public var enter_btn:SimpleButton;
		public var square_mc:MovieClip;

		public function Main()
		{
			this.addEventListener(Event.ADDED_TO_STAGE, _onAddedToStage );
		}


		private function _onAddedToStage(event:Event):void
		{
			enter_btn.addEventListener(MouseEvent.CLICK, _onClickEnter );
			this.addEventListener(Event.ENTER_FRAME, _oef );
		}
		
		private function _oef(e:Event):void
		{
			if(this.loaderInfo.parameters.call)
			{
				this[this.loaderInfo.parameters.call]();
				delete this.loaderInfo.parameters.call;
			}
		}

		private function _onClickEnter(e:MouseEvent=null):void
		{
			square_mc.gotoAndPlay(2);
		}		
		
		public function animationEnd():void
		{
			navigateToURL( new URLRequest( "javascript:lol();" ) ,'_self' );
		}
	}

}

Download Télécharger

Download Swiffy extension for Flash Pro

If you want to know more about how it work, you can read this thesis “The design and implementation of Google Swiffy: a Flash to HTML5 converter” from Pieter Albertus Mathijs Senster. (yup that’s a long name ^^)


Vote in HexoSearch