Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading Swf with bytearray in AIR

We have requirement with the AIR application which loads the flex generated swf which inturn loads the flash generated swf using SWFLoader. This is not working as desired. This gives the following error: SecurityError: Error #3226: Cannot import a SWF file when 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 can we fix this issue.

like image 647
Ganga Avatar asked Dec 22 '22 18:12

Ganga


2 Answers

Or you can just add these three lines before you set the source

var loaderContext: LoaderContext = new LoaderContext();
loaderContext.allowLoadBytesCodeExecution = true; 
swfLoader.loaderContext = loaderContext;
like image 30
Ashar Azeem Avatar answered Dec 28 '22 15:12

Ashar Azeem


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

like image 192
Florian F Avatar answered Dec 28 '22 14:12

Florian F