JS Injection
2011-09-09 12:59:21
/**
* Copyright civet ( http://wonderfl.net/user/civet )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/nVRx
*/
/**
* JavaScript injection
* reference: http://cyclingon.tumblr.com/post/9890428232/dont-get-used-to-me-posting-code-but-this-is
* 2011-09-09 12:59:21
*/
package {
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.net.URLRequest;
import flash.events.MouseEvent;
import flash.display.Sprite;
import flash.external.ExternalInterface;
import flash.net.navigateToURL;
import com.bit101.components.PushButton;
public class Test extends Sprite
{
public function Test() {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
new PushButton(this, 10, 10, "Call Javascript", onClick);
run();
}
private function onClick(e:MouseEvent):void
{
navigateToURL(new URLRequest(this.loaderInfo.url), "_blank");
}
public function run():void
{
alert("Hello Javascript!");
log("Hello Firebug!");
}
public function alert(msg:String):void
{
var code:XML = <script><![CDATA[function(msg){alert(msg);}]]></script>;
if(ExternalInterface.available) {
ExternalInterface.call(code, msg);
}
}
public function log(msg:String):void
{
var code:XML = <script><![CDATA[function(msg){console.log(msg);}]]></script>;
if(ExternalInterface.available) {
ExternalInterface.call(code, msg);
}
}
}
}