Skip to content

Instantly share code, notes, and snippets.

@steffentchr
Last active December 15, 2015 23:22

Revisions

  1. steffentchr revised this gist Dec 15, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion UpgradeToIframe.as
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@ package {
    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">';
    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);}');
  2. steffentchr created this gist Dec 15, 2015.
    42 changes: 42 additions & 0 deletions UpgradeToIframe.as
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    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">';
    }
    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);
    }
    }
    }