簡體   English   中英

在SWF文件中隱藏Javascript

[英]Hide Javascript inside SWF file

與其使用低密碼隱藏我的.JS,不如使用.SWF文件隱藏我的.JS。

問題是我對ActionScript 3不了解,所以我在想,也許有人可以在隧道盡頭告訴我,告訴我我必須下載什么APP才能對Swf文件進行編程,以及我必須使用什么代碼。為它工作。

如果有人還不了解,我會說清楚:我想使用SWF文件調用Javascript。

謝謝,抱歉英語不好,再見。

在Windows上,您可以下載FlashDevelop IDE,它將要求您下載Flex SDK(as3的免費編譯器)。

您需要了解類ExternalInterface( Reference )。

出於安全原因,您需要使用Flash Player在Web服務器上運行代碼。

在HTML中,您需要參數allowScriptAccess。

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

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