Well, it took me a little time to figure out how to select and load a local SWF file into an SWFLoader instance. Several times I got this error message:
“SecurityError: Error #3015: Loader.loadBytes() is not permitted to load content with executable code.”
After some research I found this "dreaming in flash" blog entry which basically contains the solution I was looking for.
But then it took me a little more time to figure out how to use this with the SWFLoader. So here is a basic code example:
Actionscript:
-
import flash.display.Loader;
-
import flash.filesystem.File;
-
import flash.filesystem.FileMode;
-
import flash.filesystem.FileStream;
-
import flash.system.LoaderContext;
-
import flash.utils.ByteArray;
-
import mx.controls.SWFLoader;
-
-
// File reference
-
var swfFile: File;
-
-
// Open the SWF file
-
var fileStream: FileStream = new FileStream();
-
fileStream.open( swfFile, FileMode.READ );
-
-
// Read SWF bytes into byte array and close file
-
var swfBytes: ByteArray = new ByteArray();
-
fileStream.readBytes( swfBytes );
-
fileStream.close();
-
-
// Prepare the loader context to avoid security error
-
var loaderContext: LoaderContext = new LoaderContext();
-
loaderContext.allowLoadBytesCodeExecution = true; // that's it!
-
-
// Now you could use this with a Loader instance
-
var loader: Loader = new Loader();
-
loader.loadBytes( swfBytes, loaderContext );
-
-
// Or you could use this with a SWFLoader instance
-
var swfLoader: SWFLoader = new SWFLoader();
-
swfLoader.loaderContext = loaderContext;
-
swfLoader.source = swfBytes;
I found great slides on Grant Skinners blog. They give a quick introduction in AS 3 and it's core benefits!
50 reasons why AS 3 kicks ass (Grant Skinner)
Also a must read for developers!
Update: And he also added more slides from a workshop here
Since I have to use Microsoft Word 2008 for Mac I figured out some issue: During opening a clean XHTML file with external CSS declarations Word can find these CSS files only in the same directory. I tried serveral ways to declare the href tag, but only the last one works...
HTML:
-
<link href="../style.css" rel="stylesheet" type="text/css" />
-
<link href="./../style.css" rel="stylesheet" type="text/css" />
-
<link href="..\style.css" rel="stylesheet" type="text/css" />
-
<link href="style.css" rel="stylesheet" type="text/css" />
Maybe there is a solution? I can't figure it out.
As a developer you should definitely have a look at this paper
Grant Skinners post about the (for me) unknown problem with the Flash Player GarbageCollection is definitely a must read!
One of my projects also has problems with external loaded contents wasting memory.
This is simply the link list contained in the recently released Adobe technology platform ActionScript Reference PDF.
API References
Documentation
Developer Centers
Downloads
Miscellaneous Resources
Mailing Lists
Forums
I really love the work of André Michelle and Joa Ebert, especially if it's about some cool audio stuff! But the Flash Player doesn't provide enhanced audio support, actually it seems to get worse.
So we all should support the Adobe, MAKE SOME NOISE campain!
Published on March 12, 2008
in AIR.
AIR applications are not permitted to write to the application resource directory. This seems to be a security feature and makes sense, because some systems would not allow to write into this directory at system level.
But for testing purposes you might hack this by using a single line of code:
Actionscript:
-
// Writing into that file would fail
-
var yourFileInAppDir: File = File.applicationDirectory.resolvePath( "yourFile.xml" );
-
// This is the simple hack:
-
yourFileInAppDir = new File( yourFileInAppDir.nativePath );
But this only avoids a AIR security error! You must be sure to have write access to the directory!
Just a quick note: http://www.heise.de/newsticker/meldung/101258
Adobe products are calling 2O7.net (192.168.112.2O7.net) and send statistics. Visit 2O7.net to disable this.