将加密的 swf 加载到 flex builder 中的 swfLoader 中



我想在flex builder中将加密的swf加载到SWFLoader中。这是我尝试过的代码。我收到错误类型错误:错误 #1006:值不是函数。 请给我解决方案。我将制作加密的 swf 加载器。

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
                    xmlns:ns1="*"
                    width="100%" height="100%" layout="absolute" name="Content"
                    showStatusBar="false" applicationComplete="decrypt()">
<mx:Script> 
    <![CDATA[
        import com.hurlant.crypto.symmetric.AESKey;
        import com.hurlant.crypto.symmetric.DESKey;
        import com.hurlant.util.Hex;
        import flash.net.FileFilter;
        import flash.net.FileReference;
        import flash.utils.ByteArray;
        import mx.controls.Alert;
        import mx.controls.SWFLoader;
        import mx.preloaders.Preloader;

        private static var stream:FileStream;
        private static var stream2:FileStream;
        private static var file:File;
        private var fileToEncrypt:ByteArray;
        private function decrypt():void
        {
            file = File.documentsDirectory.resolvePath("E:/Sampal.swf");
            fileToEncrypt = new ByteArray;
            stream = new FileStream();
            stream.open( file, FileMode.READ );
            stream.readBytes(fileToEncrypt);
            stream.close();
            var key:ByteArray = Hex.toArray("gayan123");
            var aes:AESKey = new AESKey(key);
            aes.decrypt(fileToEncrypt);

            loader.load(fileToEncrypt)
            //stream2 = new FileStream();
            //stream2.open( file, FileMode.READ);
            //stream2.writeBytes(fileToEncrypt);
            //stream2.close();
        }
    ]]>
</mx:Script>
<mx:SWFLoader id="loader" x="0" y="0" width="900" height="550" autoLoad="true"
              includeInLayout="true" scaleContent="true"/>
</mx:WindowedApplication>

在不研究您正在执行的操作的加密/解密方面的情况下,您需要在Loader类中使用的方法是 loadBytes() ,在您的情况下,它将异步解析ByteArray为图像或 SWF。

以下是您的使用方法:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
                    xmlns:ns1="*"
                    width="100%" height="100%" layout="absolute" name="Content"
                    showStatusBar="false" applicationComplete="decrypt()">
<mx:Script> 
    <![CDATA[
        import com.hurlant.crypto.symmetric.AESKey;
        import com.hurlant.crypto.symmetric.DESKey;
        import com.hurlant.util.Hex;
        import flash.display.Loader;
        import flash.net.FileFilter;
        import flash.net.FileReference;
        import flash.utils.ByteArray;
        import flash.events.Event;
        import flash.system.LoaderContext;
        import mx.controls.Alert;
        import mx.controls.SWFLoader;
        import mx.preloaders.Preloader;
        private var decryptionLoader:Loader;
        private static var stream:FileStream;
        private static var stream2:FileStream;
        private static var file:File;
        private var fileToEncrypt:ByteArray;

        private function decrypt():void
        {
            file = File.documentsDirectory.resolvePath("E:/Sampal.swf");
            fileToEncrypt = new ByteArray;
            stream = new FileStream();
            stream.open( file, FileMode.READ );
            stream.readBytes(fileToEncrypt);
            stream.close();
            var key:ByteArray = Hex.toArray("gayan123");
            var aes:AESKey = new AESKey(key);
            aes.decrypt(fileToEncrypt);
            decryptionLoader = new Loader();
            decryptionLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, decryptionLoader_complete);
            var lc:LoaderContext = new LoaderContext();
            lc.allowLoadBytesCodeExecution = true; 
            decryptionLoader.loadBytes(fileToEncrypt, lc);
            //stream2 = new FileStream();
            //stream2.open( file, FileMode.READ);
            //stream2.writeBytes(fileToEncrypt);
            //stream2.close();
        }
        private function decryptionLoader_complete(evt:Event):void {
            decryptionLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loader_complete);
            //Your SWF has now been parsed and is ready to use e.g.:
            this.addChild(decryptionLoader.content);
        }
    ]]>
</mx:Script>
<mx:SWFLoader id="loader" x="0" y="0" width="900" height="550" autoLoad="true"
              includeInLayout="true" scaleContent="true"/>
</mx:WindowedApplication>

最新更新