0

我想将加密的 swf 加载到 flex builder 中的 SWFLoader 中。这是我尝试过的代码。我收到一个错误TypeError: Error #1006: value is not a function。请给我解决方案。我将制作加密的 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>
4

1 回答 1

0

在不查看您正在做的事情的加密/解密方面,您需要在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>
于 2013-09-18T09:17:37.317 回答