Reputation: 75
Instead of hidding my .JS using low criptography, I would prefer using a .SWF file to hide my .JS.
The problem is i have no knowledge in ActionScript 3, so i was thinking that maybe someone could give me a light in the end of the tunnel and tell me what APP i have to download to program the Swf file and what code i have to use for it to work.
If somebody haven't undestood i'll make it clear: I want to call Javascript using a SWF file.
Thank you, sorry for the bad english and good bye.
Upvotes: 1
Views: 245
Reputation: 640
On Windows, you can download FlashDevelop IDE, it will ask you to download Flex SDK ( the free compiler for as3 ).
You need to understand the class ExternalInterface (Reference).
You need to run your code on webserver for security reason with the flash player.
In HTML, you need the param allowScriptAccess.
HTML CallJavascript
<script src="js/swfobject.js"></script>
<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
<script>
var flashvars = {
};
var params = {
menu: "false",
scale: "noScale",
allowFullscreen: "true",
allowScriptAccess: "always",
bgcolor: "",
wmode: "direct" // can cause issues with FP settings & webcam
};
var attributes = {
id:"CallJavascript"
};
swfobject.embedSWF(
"CallJavascript.swf",
"altContent", "250", "250", "10.0.0",
"expressInstall.swf",
flashvars, params, attributes);
$( document ).ready(function() {
var flash = document.getElementById("CallJavascript");
$( "#btnSend" ).click(function() {
flash.jsMySecretMethod( $( "#field" ).val() );
});
});
</script>
<style>
html, body { height:100%; overflow:hidden; }
body { margin:0; background-color:#c0c0c0 }
</style>
</head>
<body>
<div id="altContent">
<h1>CallJavascript</h1>
<p><a href="http://www.adobe.com/go/getflashplayer">Get Adobe Flash player</a></p>
</div>
<input id="field" type="text"/><button id="btnSend">Send</button>
</body>
</html>
AS3
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.external.ExternalInterface;
import flash.text.TextField;
/**
* ...
* @author
*/
public class Main extends Sprite
{
private var _textfield:TextField;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
_textfield = new TextField();
_textfield.multiline = true;
_textfield.wordWrap = true;
_textfield.x = 20;
_textfield.y = 20;
_textfield.width = 200;
_textfield.height = 200;
_textfield.textColor = 0x000000;
_textfield.text = "start";
_textfield.border = true;
addChild( _textfield );
if ( ExternalInterface.available ) {
ExternalInterface.addCallback( "jsMySecretMethod", mySecretMethod );
}
}
private function mySecretMethod( str:String ):void {
trace( str );
_textfield.appendText( str );
}
}
}
Upvotes: 1