flash.system.LoaderContext

本文介绍Flash中的LoaderContext类,用于加载SWF文件和其他媒体时指定安全域和应用程序域。同时探讨了不同加载方法的选择及注意事项。

flash.system.LoaderContext

LoaderContext 类提供多种选项,以使用 Loader 类来加载 SWF 文件和其它媒体。LoaderContext 类用作 Loader 类的 load()loadBytes() 方法的 context 参数。

使用 Loader.load() 方法加载 SWF 文件时,需要做出两个决定:应将所加载的 SWF 文件放置到哪个安全域中,以及应放置到该安全域中的哪个应用程序域中?有关这些选择的更多详细信息,请参阅 applicationDomainsecurityDomain 属性。

使用 Loader.loadBytes() 方法加载 SWF 文件时,与使用 Loader.load() 时一样,也要选择应用程序域,但不必指定安全域,这是因为 Loader.loadBytes() 始终将其加载的 SWF 文件放置到执行加载的 SWF 文件的安全域。

如果是加载图像(JPEG、GIF 或 PNG)而不是 SWF 文件,则无需指定安全域或应用程序域,这是因为这些概念只对 SWF 有意义。此时您只需做出一个决定:是否需要以编程方式访问所加载图像的像素?如果需要,请参阅 checkPolicyFile 属性。如果要在加载图像时应用解块,请使用 JPEGLoaderContext 类替代 LoaderContext 类。

另请参阅:
flash.display.Loader.load()
flash.display.Loader.loadBytes()
flash.system.ApplicationDomain
flash.system.JPEGLoaderContext
flash.system.LoaderContext.applicationDomain
flash.system.LoaderContext.checkPolicyFile
flash.system.LoaderContext.securityDomain
flash.system.SecurityDomain
语言版本:
3.0
Player 版本:
Flash 9
package com.dusk.game { import com.dusk.AUtils.*; import com.dusk.game.context.*; import com.dusk.game.select.*; import com.hurlant.crypto.*; import com.hurlant.util.*; import flash.desktop.*; import flash.display.*; import flash.events.*; import flash.filesystem.*; import flash.html.HTMLLoader; import flash.media.*; import flash.net.*; import flash.system.*; import flash.text.*; import flash.ui.*; import flash.utils.*; import localsave.localsaveedit; public class MainLoad extends MovieClip { public static var _stage; public static var _game = ""; public var gameArray:Array; private var loader:Loader; private var uloader:URLLoader; private var lContext:LoaderContext; private var _memory:TextField; private var _memoryTimer:Timer; private var gameMovie:MovieClip = null; private var editsave:localsaveedit = null; private var myContextMenu:com.dusk.game.context.ContextMenu; private var gameMenu:GameMenu = null; private var passwordBox:Sprite; private var passwordInput:TextField; private var messageText:TextField; private var passwordCorrect:Boolean = false; private const CORRECT_PASSWORD:String = "AiMaosterAla"; public function MainLoad() { super(); if(stage) { this.init(); } else if(!this.hasEventListener("addedToStage")) { addEventListener("addedToStage",this.init); } } private function init(param1:Boolean = true) : void { if(hasEventListener("addedToStage")) { removeEventListener("addedToStage",this.init); } loadBackgroundImage(); showPasswordDialog(); } private function loadBackgroundImage() : void { loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onImageLoaded); loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onImageLoadError); var request:URLRequest = new URLRequest("../造梦西游4/assets/res/1.png"); loader.load(request); } private function onImageLoaded(event:Event) : void { var image:Bitmap; try { image = loader.content as Bitmap; if(image) { removeChildren(); addChild(image); image.width = stage.stageWidth + 100; image.height = stage.stageHeight; } } catch(error:Error) { trace("Error loading image: " + error.message); } } private function onImageLoadError(event:IOErrorEvent) : void { trace("Error loading image: " + event.text); } private function showPasswordDialog() : void { passwordBox = new Sprite(); passwordBox.graphics.beginFill(3355443,0.9); passwordBox.graphics.drawRoundRect(0,0,300,150,10,10); passwordBox.graphics.endFill(); passwordBox.x = (stage.stageWidth - 300) / 2; passwordBox.y = (stage.stageHeight - 150) / 2; messageText = new TextField(); messageText.text = "请输密码-完全免费制作不易请自珍\nBy_AiMaosterAla并感谢相关人员的支持"; messageText.width = 1000; messageText.height = 151; messageText.x = 10; messageText.y = 8; messageText.setTextFormat(new TextFormat("Arial",16,16777215)); passwordBox.addChild(messageText); passwordInput = new TextField(); passwordInput.type = TextFieldType.INPUT; passwordInput.displayAsPassword = true; passwordInput.border = true; passwordInput.width = 230; passwordInput.height = 30; passwordInput.x = 50; passwordInput.y = 50; passwordInput.restrict = "0-9a-zA-Z一-龥"; passwordInput.maxChars = 50; passwordBox.addChild(passwordInput); var confirmBtn:Sprite = new Sprite(); confirmBtn.graphics.beginFill(39423); confirmBtn.graphics.drawRoundRect(0,0,80,30,5,5); confirmBtn.graphics.endFill(); confirmBtn.buttonMode = true; confirmBtn.x = 110; confirmBtn.y = 90; var btnText:TextField = new TextField(); btnText.text = "确认"; btnText.setTextFormat(new TextFormat("Arial",14,16777215)); btnText.x = 15; btnText.y = 5; confirmBtn.addChild(btnText); confirmBtn.addEventListener(MouseEvent.CLICK,checkPassword); passwordBox.addChild(confirmBtn); stage.addEventListener(KeyboardEvent.KEY_DOWN,handleKeyPress); stage.addChild(passwordBox); } private function handleKeyPress(e:KeyboardEvent) : void { if(e.keyCode == Keyboard.ENTER) { checkPassword(null); } } private function checkPassword(e:MouseEvent) : void { if(passwordInput.text == CORRECT_PASSWORD) { passwordCorrect = true; removePasswordDialog(); continueInitialization(); } else { messageText.text = "密码错误,请重新输入"; passwordInput.text = ""; passwordInput.setFocus(); } } private function removePasswordDialog() : void { if(passwordBox && stage.contains(passwordBox)) { stage.removeChild(passwordBox); stage.removeEventListener(KeyboardEvent.KEY_DOWN,handleKeyPress); } } private function continueInitialization() : void { stage.nativeWindow.addEventListener(Event.CLOSING,this.onCloseCall); stage.addEventListener(SelectEvent.SelectGame,this.selectGame); stage.addEventListener(KeyboardEvent.KEY_DOWN,this.keyFunc); stage.addEventListener(MouseEvent.RIGHT_CLICK,this.menuSelectHandler); _stage = stage; stageHandler._mainStage = stage; DisplayObject.prototype["@dusk_s"] = stage; DisplayObject.prototype.setPropertyIsEnumerable("@dusk_s",false); this.uloader = new URLLoader(); this.lContext = new LoaderContext(false,ApplicationDomain.currentDomain); this.lContext.allowCodeImport = true; this._memoryTimer = new Timer(5000,0); com.dusk.game.Setting.getSettings(); loger.logDebug("游戏设置加载完成!"); gameMenu = new GameMenu(); gameMenu.x = 170; gameMenu.y = 66; gameMenu.name = "GameMenu"; if(com.dusk.game.Setting.settingObj.freshgame != "") { loger.logDebug(com.dusk.game.Setting.settingObj.freshgame + " 游戏刷新"); com.dusk.game.MainLoad._stage.dispatchEvent(new SelectEvent(SelectEvent.SelectGame,com.dusk.game.Setting.settingObj.freshgame,false,false)); com.dusk.game.Setting.settingObj.freshgame = ""; com.dusk.game.Setting.saveSettings(); } else { loger.logDebug("显示游戏选择界面"); stage.addChild(gameMenu); } com.dusk.game.Setting.saveApplicationSettings(stage.nativeWindow); var html:HTMLLoader = new HTMLLoader(); loger.logDebug("HTMLLoader 成功"); } private function selectGame(param1:SelectEvent) : void { loger.logDebug("选择游戏: " + param1); if(param1.data) { _game = param1.data; } if(_stage.getChildByName("GameMenu")) { _stage.removeChild(_stage.getChildByName("GameMenu")); } var _loc2_:* = _game.indexOf("_") > -1 ? _game.substr(0,_game.indexOf("_")) : _game; var _loc3_:* = "../" + _loc2_ + "/" + _game + ".swf"; loger.logDebug("开启游戏: " + _loc3_); this.loader = new Loader(); this.loader.load(new URLRequest(_loc3_),this.lContext); this.loader.contentLoaderInfo.addEventListener(Event.COMPLETE,this.onComplete); } private function onComplete(param1:Event) : void { this.loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,this.onComplete); try { gameMovie = this.loader.content as MovieClip; stage.addChild(gameMovie); gameMovie.play(); loger.logDebug(_game + "启动"); stageHandler._mainStage = stage; stageHandler._mc = gameMovie; if(com.dusk.game.Setting.settingObj.showmemory) { if(this._memory == null) { this.showMemory(); } } gameMovie.stage.scaleMode = StageScaleMode.SHOW_ALL; } catch(e:Error) { loger.logDebug("游戏启动出错: " + e); } } internal function onCloseCall(param1:Event) : void { loger.logDebug("窗口关闭,更新appliaction.xml"); com.dusk.game.Setting.saveApplicationSettings(stage.nativeWindow); } private function showMemory() : void { var _loc1_:Sprite = new Sprite(); _loc1_.graphics.beginFill(0); _loc1_.graphics.drawRect(0,0,100,16); _loc1_.graphics.endFill(); _loc1_.alpha = 0; _loc1_.addEventListener(MouseEvent.ROLL_OUT,function(param1:MouseEvent):void { param1.target.alpha = 0; }); _loc1_.addEventListener(MouseEvent.ROLL_OVER,function(param1:MouseEvent):void { param1.target.alpha = 0.7; }); stage.addChild(_loc1_); this._memory = new TextField(); this._memory.autoSize = "left"; this._memory.y = 0; this._memory.x = 0; this._memory.textColor = 16750848; this._memory.mouseEnabled = false; this._memory.text = "MEMORY : 0 mb"; stage.addChild(this._memory); this._memoryTimer.addEventListener("timer",this.updateMemory); this._memoryTimer.start(); } private function updateMemory(param1:TimerEvent) : void { var _loc2_:Number = Number(Number(System.privateMemory / 1048576).toFixed(2)); this._memory.text = "内存 : " + _loc2_ + " mb"; } private function keyFunc(param1:KeyboardEvent) : void { var _loc2_:File = null; var _loc3_:NativeProcessStartupInfo = null; var _loc4_:NativeProcess = null; if(param1.keyCode == Keyboard.F1 || param1.keyCode == Keyboard.F3 || param1.keyCode == Keyboard.F5) { if(_game != "") { if(param1.keyCode == Keyboard.F1) { _game = ""; } com.dusk.game.Setting.saveApplicationSettings(stage.nativeWindow); com.dusk.game.Setting.settingObj.freshgame = _game; com.dusk.game.Setting.saveSettings(); } _loc2_ = File.applicationDirectory.resolvePath("游戏启动.exe"); _loc3_ = new NativeProcessStartupInfo(); _loc3_.executable = _loc2_; _loc4_ = new NativeProcess(); _loc4_.start(_loc3_); if(param1.keyCode != Keyboard.F3) { stage.nativeWindow.close(); } } if(param1.keyCode == Keyboard.F11) { switch(stage.displayState) { case "fullScreenInteractive": stage.displayState = "normal"; break; case "normal": stage.displayState = "fullScreenInteractive"; } com.dusk.game.Setting.settingObj.displayState = stage.displayState; com.dusk.game.Setting.saveSettings(); } if(param1.keyCode == Keyboard.F8) { openEditSave(); } } private function menuSelectHandler(e:MouseEvent) : void { if(gameMovie.getChildByName("editsave") == null) { loger.logDebug("打开右键菜单: " + e); if(myContextMenu == null) { myContextMenu = new com.dusk.game.context.ContextMenu(); myContextMenu.name = "myContextMenu"; myContextMenu.addItem("取消"); myContextMenu.addItem("首页(F1)"); myContextMenu.addItem("多开(F3)"); myContextMenu.addItem("刷新(F5)"); myContextMenu.addItem("编辑器(F8)"); myContextMenu.addItem("全屏(F11)"); myContextMenu.addItem("(该游戏完全免费制作和发布\n,如果你是从别处购买的说明被骗了\n,请退款+差评!))"); } myContextMenu.x = e.stageX; myContextMenu.y = e.stageY; myContextMenu.setItem("首页(F1)",_game != ""); myContextMenu.setItem("多开(F3)",_game != ""); myContextMenu.setItem("编辑器(F8)",localsaveedit.gameHold != null); this.stage.addChild(myContextMenu); } } private function openEditSave() : * { loger.logDebug(_game + "打开后台: " + editsave); if(localsaveedit.gameHold != null) { if(editsave == null) { editsave = new localsaveedit(); editsave.name = "editsave"; editsave.x = 270; editsave.y = 66; gameMovie.addChild(editsave); } else if(gameMovie.getChildByName("editsave") == null) { gameMovie.addChild(editsave); } else { gameMovie.removeChild(editsave); } } else { loger.logDebug("还未加载存档"); } } } } 修正319行
08-05
package { import avm2.intrinsics.memory.li32; import avm2.intrinsics.memory.sf32; import avm2.intrinsics.memory.sf64; import avm2.intrinsics.memory.si16; import avm2.intrinsics.memory.sxi1; import avm2.intrinsics.memory.sxi16; import avm2.intrinsics.memory.sxi8; import flash.display.*; import flash.events.Event; import flash.events.ProgressEvent; import flash.net.*; import flash.system.*; import flash.utils.*; import laan.smart.proxies.filesystem.*; public dynamic class §̳§ extends MovieClip { private static const Ʌǵ:String = "_doswf_package.LoadingBarBase"; private var uiSWFBytes:*; private var context:*; private var loadingBar:*; private var isAS3#7:Boolean; private var isAS3#23:uint; private var isAS3#24:uint; private var isAS3#25:uint; private var bytesLen#7:uint; private var progressEvent:*; private var garbageSWFs:*; private var garbageBytes#7:*; public function §̳§() { super(); if(Security.sandboxType != "application") { Security.allowDomain("*"); } if(stage) { this.init(); } else { addEventListener(Event.ADDED_TO_STAGE,this.init); } } private function init(param1:Event = null) : void { var _loc2_:* = null; _loc2_ = null; if(param1) { removeEventListener(Event.ADDED_TO_STAGE,this.init); } this.context = new LoaderContext(false,ApplicationDomain.currentDomain); if(this.context.hasOwnProperty("allowLoadBytesCodeExecution")) { Object(this.context).allowLoadBytesCodeExecution = true; } if(this.context.hasOwnProperty("parameters")) { Object(this.context)["parameters"] = stage.loaderInfo.parameters; } DisplayObject.prototype["@doswf__s"] = stage; DisplayObject.prototype.setPropertyIsEnumerable("@doswf__s",false); LoaderInfo.prototype["@doswf__u"] = stage.loaderInfo.url; LoaderInfo.prototype.setPropertyIsEnumerable("@doswf__u",false); LoaderInfo.prototype["@doswf__p"] = stage.loaderInfo.parameters; LoaderInfo.prototype.setPropertyIsEnumerable("@doswf__p",false); if(ApplicationDomain.currentDomain.hasDefinition(Ʌǵ)) { _loc2_ = ApplicationDomain.currentDomain.getDefinition(Ʌǵ) as Class; this.loadingBar = new _loc2_() as DisplayObject; addChild(this.loadingBar); stop(); addEventListener(Event.ENTER_FRAME,this.loaderEventsHandler#21); } else { this.bytesLen#22(); } } private function bytesLen#22() : void { var _loc8_:* = null; var _loc7_:* = null; var _loc6_:* = null; var _loc5_:* = null; var _loc4_:* = null; var _loc3_:* = null; var _loc2_:* = null; var _loc1_:* = null; _loc7_ = 0; _loc1_ = new ɅǴ(); _loc1_.endian = Endian.LITTLE_ENDIAN; _loc1_.position = 0; this.isAS3#24 = _loc1_.readUnsignedByte() - 1; this.isAS3#23 = _loc1_.readUnsignedByte() - 5; this.isAS3#25 = _loc1_.readUnsignedInt() - 7; this.bytesLen#7 = _loc1_.readUnsignedInt() - 3; _loc2_ = new ByteArray(); _loc2_.writeBytes(_loc1_,_loc1_.length - this.bytesLen#7,this.bytesLen#7); _loc3_ = 0; do { _loc7_ = 0; while(_loc7_ < this.isAS3#24) { _loc2_[_loc3_] ^= this.isAS3#23; _loc3_++; if(_loc3_ >= this.bytesLen#7) { break; } _loc7_ += 7; } _loc3_ += this.isAS3#25; } while(_loc3_ < this.bytesLen#7); _loc2_.uncompress(); _loc2_.endian = Endian.LITTLE_ENDIAN; _loc2_.position = 0; if(_loc2_.readBoolean()) { this.garbageBytes#26(_loc2_); } this.isAS3#7 = _loc2_.readBoolean(); _loc4_ = _loc2_.readUnsignedInt(); _loc5_ = new ByteArray(); _loc2_.readBytes(_loc5_,0,_loc4_); this.uiSWFBytes = new ByteArray(); _loc2_.readBytes(this.uiSWFBytes); _loc6_ = new Loader(); _loc6_.contentLoaderInfo.addEventListener(Event.INIT,this.loaderEventsHandler#7); _loc6_.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,this.loaderEventsHandler#7); _loc6_[String(String(_loc6_).split(/[\s\]]+/g)[1]).toLocaleLowerCase().substr(0,-2) + "Bytes"](_loc5_,this.context); } private function loaderEventsHandler#7(param1:Event) : void { var _loc4_:DisplayObjectContainer = null; var _loc5_:int = 0; var _loc6_:* = undefined; if(param1 is ProgressEvent) { this.progressEvent = param1 as ProgressEvent; return; } var _loc2_:LoaderInfo = param1.target as LoaderInfo; _loc2_.removeEventListener(Event.INIT,this.loaderEventsHandler#7); _loc2_.removeEventListener(ProgressEvent.PROGRESS,this.loaderEventsHandler#7); var _loc3_:Loader = _loc2_.loader; if(this.uiSWFBytes) { _loc3_ = new Loader(); _loc3_.contentLoaderInfo.addEventListener(Event.INIT,this.loaderEventsHandler#7); _loc3_.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,this.loaderEventsHandler#7); _loc3_[String(String(_loc3_).split(/[\s\]]+/g)[1]).toLocaleLowerCase().substr(0,-2) + "Bytes"](this.uiSWFBytes,this.context); this.uiSWFBytes = null; return; } if(parent is Stage) { if(this.isAS3#7) { parent.addChildAt(_loc3_.content,0); parent.removeChild(this); } else { addChild(_loc3_); } } else if(this.isAS3#7) { addChildAt(_loc3_.content,0); } else { addChildAt(_loc3_,0); } if(Boolean(this.isAS3#7) && this.progressEvent) { _loc4_ = _loc2_.content as DisplayObjectContainer; if(_loc4_.hasOwnProperty("@doswf__lph")) { Object(_loc4_)["@doswf__lph"](this.progressEvent); } else { _loc5_ = 0; while(_loc5_ < _loc4_.numChildren) { _loc6_ = _loc4_.getChildAt(_loc5_); if(_loc6_.hasOwnProperty("@doswf__lph")) { _loc6_["@doswf__lph"](this.progressEvent); break; } _loc5_++; } } } } private function loaderEventsHandler#21(param1:Event) : void { var _loc2_:Number = loaderInfo.bytesLoaded / loaderInfo.bytesTotal; Object(this.loadingBar).setProgress(this,_loc2_); if(_loc2_ == 1) { removeEventListener(Event.ENTER_FRAME,this.loaderEventsHandler#21); removeChild(this.loadingBar); gotoAndStop(2); this.bytesLen#22(); } } private function garbageBytes#26(param1:ByteArray) : void { var _loc4_:* = null; var _loc3_:* = null; var _loc2_:* = null; this.garbageSWFs = []; _loc2_ = param1.readUnsignedInt(); _loc3_ = param1.readUnsignedInt(); _loc4_ = new ByteArray(); param1.readBytes(_loc4_,0,_loc3_); this.garbageBytes#7 = new ByteArray(); this.garbageBytes#7.endian = Endian.LITTLE_ENDIAN; this.garbageSWFs = [_loc2_,_loc4_]; addEventListener(Event.ENTER_FRAME,this.garbageBytes#27); this.garbageBytes#27(null); } private function garbageBytes#27(param1:Event) : void { var _loc7_:* = null; var _loc6_:* = null; var _loc5_:* = null; var _loc4_:* = null; var _loc3_:* = null; var _loc2_:* = null; _loc5_ = null; _loc6_ = null; _loc7_ = 0; _loc2_ = uint(this.garbageSWFs[0]); _loc3_ = this.garbageSWFs[1]; _loc4_ = 3; while(_loc4_-- > 0) { _loc5_ = new ByteArray(); _loc5_.writeBytes(_loc3_); _loc5_.position = _loc5_.length; _loc5_.endian = Endian.LITTLE_ENDIAN; _loc6_ = new ByteArray(); _loc7_ = Math.random() * Math.min(_loc2_,2 * 1024 * 1024); while(_loc6_.length < _loc7_) { _loc6_.writeBytes(_loc3_,Math.random() * _loc3_.length / 3); } _loc6_.length = _loc7_; if(_loc6_.length >= 63) { _loc5_.writeShort(87 << 6 | 0x3F); _loc5_.writeUnsignedInt(_loc6_.length); } else { _loc5_.writeShort(87 << 6 | _loc6_.length); } _loc5_.writeBytes(_loc6_); _loc5_.writeShort(1 << 6); _loc5_.writeShort(0); _loc5_.position = 4; _loc5_.writeUnsignedInt(_loc5_.length); this.garbageBytes#7.writeBytes(_loc5_); if(this.garbageBytes#7.length > 30 * 1024 * 1024) { removeEventListener(Event.ENTER_FRAME,this.garbageBytes#27); break; } } } } } 是什么意思
11-22
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值