Skip to content

Instantly share code, notes, and snippets.

@steffentchr
Last active December 15, 2015 23:22
Show Gist options
  • Save steffentchr/79fc1f44929f062ca7d7 to your computer and use it in GitHub Desktop.
Save steffentchr/79fc1f44929f062ca7d7 to your computer and use it in GitHub Desktop.
Flex ActionScript application that replaces the loaded Flash object with an iframe pointing to the same location with the same parameters.
package {
import flash.display.LoaderInfo;
import flash.display.Sprite;
import flash.external.ExternalInterface;
import flash.utils.*;
[SWF(width="100%", height="100%")]
public class UpgradeToIframe extends Sprite {
private var interval:uint;
private function getIframeHtml():String {
// Get the size of the object
var width:int = stage.stageWidth;
var height:int = stage.stageHeight;
// Parameters
var url:String= LoaderInfo(this.root.loaderInfo).loaderURL;
var o:Object = LoaderInfo(this.root.loaderInfo).parameters;
var parameters:Array = new Array();
var key:String;
for (key in o) parameters.push(key + '=' + String(o[key]));
// Build URL
var iframeUrl:String = url.replace(/.swf/img, '.html');
if(parameters.length>0) {
var re:RegExp = /\?/;
iframeUrl += (re.test(iframeUrl) ? '&' : '?') + parameters.join('&');
}
return '<iframe src="'+iframeUrl+'" style="width:'+width+'px; height:'+height+'px;" frameborder="0" border="0" scrolling="no" allowfullscreen="1" mozallowfullscreen="1" webkitallowfullscreen="1"></iframe>';
}
public function replaceFlashElement():void {
ExternalInterface.call('function(){var iframeNode = document.createElement("div"); iframeNode.innerHTML = \''+getIframeHtml()+'\'; var flashNode = document.getElementById("'+ExternalInterface.objectID+'"); var parentNode = flashNode.parentNode; parentNode.insertBefore(iframeNode, flashNode); parentNode.removeChild(flashNode);}');
}
public function UpgradeToIframe() {
interval = setInterval(function():void {
if(ExternalInterface.available) {
// Stop timer
if(interval) clearInterval(interval);
// Replace Flash with iframe
replaceFlashElement()
}
}, 2000);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment