简体   繁体   English

在SWF文件中隐藏Javascript

[英]Hide Javascript inside SWF file

Instead of hidding my .JS using low criptography, I would prefer using a .SWF file to hide my .JS. 与其使用低密码隐藏我的.JS,不如使用.SWF文件隐藏我的.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. 问题是我对ActionScript 3不了解,所以我在想,也许有人可以在隧道尽头告诉我,告诉我我必须下载什么APP才能对Swf文件进行编程,以及我必须使用什么代码。为它工作。

If somebody haven't undestood i'll make it clear: I want to call Javascript using a SWF file. 如果有人还不了解,我会说清楚:我想使用SWF文件调用Javascript。

Thank you, sorry for the bad english and good bye. 谢谢,抱歉英语不好,再见。

On Windows, you can download FlashDevelop IDE, it will ask you to download Flex SDK ( the free compiler for as3 ). 在Windows上,您可以下载FlashDevelop IDE,它将要求您下载Flex SDK(as3的免费编译器)。

You need to understand the class ExternalInterface ( Reference ). 您需要了解类ExternalInterface( Reference )。

You need to run your code on webserver for security reason with the flash player. 出于安全原因,您需要使用Flash Player在Web服务器上运行代码。

In HTML, you need the param allowScriptAccess. 在HTML中,您需要参数allowScriptAccess。

HTML CallJavascript HTML调用Javascript

    <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 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 );
        }

    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM