Get current url to Flash swf without using External Interface call

Note it’s “without using External Interface call”,and I found out an interesting way to get current page url to Flash by FMS.

In swf:

package 
{
	import flash.display.Sprite;
	import flash.net.NetConnection;
	import flash.events.NetStatusEvent;
	import flash.net.Responder;

	public class Link extends Sprite
	{
		var nc:NetConnection;

		public function Link()
		{
			nc = new NetConnection();
			nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
			nc.connect("rtmp://server_url/app");
		}
		public function __onRes(arg:String):void
		{
			trace("current html page url:" + arg);
			nc.close();
		}


		private function netStatusHandler(event:NetStatusEvent):void
		{
			switch (event.info.code)
			{
				case "NetConnection.Connect.Success" :
					var ro:Responder = new Responder(__onRes);
					nc.call("getPageUrl", ro);
					break;
			}
		}
	}
}

FMS server side ASC file:

application.onConnect = function(client)
{
    this.acceptConnection(client); 
    client.getPageUrl = function(msg)
    {
        return this.pageUrl;
    };
};

Haha,hope you like it!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s