我想在flex builder中将加密的swf加载到SWFLoader中。这是我试过的代码。 我收到错误 TypeError:错误#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>
答案 0 :(得分: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>