Flex – Use ByteArray to load SWF in AIR

We require the AIR application to load the swf generated by flex, which uses SWFLoader to load the swf generated by flash. This does not meet the requirements. This will cause the following error:
SecurityError: Error #3226 : When LoaderContext.allowCodeImport is false, the SWF file cannot be imported.

This is our AIR application.





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;
swf Loader.percentHeight = vbox.height;
swfLoader.percentWidth = vbox.width;
swfLoader.invalidateDisplayList();
swfLoader.invalidateSize();

// now add the swfloader into container
vbox.addChild(swfLoader);
}

]]>







Please tell us how to solve this problem.

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

We require the AIR application to load the swf generated by flex, which uses SWFLoader to load the swf generated by flash. This does not meet the requirements. This will cause the following error:
SecurityError: Error# 3226: When LoaderContext.allowCodeImport is false, the SWF file cannot be imported.

This is our AIR application.





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>





Please tell us how to solve this problem.

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

Leave a Comment

Your email address will not be published.