Download Swf with bytearray in AIR

We have a requirement with an AIR application that loads the generated generated swf, which inturn loads the generated swf flash using SWFLoader. This does not work as desired. This gives the following error: SecurityError: Error # 3226: Unable to import SWF file if LoaderContext.allowCodeImport is false.

This is our AIR application.

<?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()"> <mx:Script> <![CDATA[ import mx.controls.SWFLoader; [Embed(source="FlexLoadingFlash.swf")] public var flexMovie:Class; private function initApp():void { // First convert the Swf into MovieClip var movieclip:MovieClip = new flexMovie(); // get the byteArray from movieClip var byteArray:ByteArray = movieclip.movieClipData; var swfLoader:SWFLoader = new SWFLoader(); // load bytearray into swfLoader swfLoader.source = byteArray; swfLoader.maintainAspectRatio = false; swfLoader.percentHeight = vbox.height; swfLoader.percentWidth = vbox.width; swfLoader.invalidateDisplayList(); swfLoader.invalidateSize(); // now add the swfloader into container vbox.addChild(swfLoader); } ]]> </mx:Script> <mx:VBox id="vbox" width="100%" height="100%" verticalCenter="0" horizontalCenter="0" cacheAsBitmap="true" > </mx:VBox> </mx:WindowedApplication> 

Please let me know how we can fix this problem.

+4
source share
3 answers

Use Loader.loadBytes () to load the SWF. Create an instance of LoaderContext. The loadBytes method takes an instance of LoaderContext as a parameter. Set the allowCodeImport property of your LoaderContext instance to true and it should work

+7
source

Or you can simply add these three lines before setting the source

 var loaderContext: LoaderContext = new LoaderContext(); loaderContext.allowLoadBytesCodeExecution = true; swfLoader.loaderContext = loaderContext; 
+2
source
 <mx:SWFLoader id="swfObj" width="100%" height="100%" complete="swfObj_completeHandler(event)"/> <fx:Script> <![CDATA[ [Bindable] [Embed(source="assets/soundbar.swf")] private static var swfClass:Class; private var swfSoundBar : MovieClip; [Bindable] private var mp3Player:MP3Player = MP3Player.getInstance(); protected function init(event:FlexEvent):void { swfSoundBar = new swfClass(); var byteArray:ByteArray = swfSoundBar.movieClipData; var loaderContext: LoaderContext = new LoaderContext(); loaderContext.allowLoadBytesCodeExecution = true; swfObj.loaderContext = loaderContext; swfObj.source = byteArray; } protected function swfObj_completeHandler(event:Event):void { swfSoundBar = SWFLoader(event.target).content as MovieClip; swfSoundBar.width = 32; swfSoundBar.height = 14; swfSoundBarShowHide(); } protected function swfSoundBarShowHide():void { if (swfSoundBar){ if (mp3Player.isPlaying){ swfSoundBar.gotoAndStop(0); swfSoundBar.stop(); } else { swfSoundBar.gotoAndPlay(0); } } } ]]> </fx:Script> 
+2
source

Source: https://habr.com/ru/post/1336911/


All Articles