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
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
Wow, this was really challenging! But now, finally, I found out how to use AsDoc on my Mac.There must be another solution out there, but I simply want to document this workaround hoping that this also works on your Mac.
What you need is a Flex SDK 2.0.1 which comes with Flex Builder or as a free download from Adobe and the knowledge how to use ANT (I use eclipse).
I tried this tutorial several times but it never worked for me. I don't know why.But after hours of testing I hopefully found a proper solution which works find with Flex SDK 2.0.1. The main idea simply is separating the AsDoc functionality from the normal Flex Builder environment. Basically the only thing you have to do is avoiding whitespaces from your directory names. However I tried to use Flex Builder for this and Flex Builder installs into the directory "Flex Builder 3".So this is what I did and you might try:
- Create a new directory within the applications folder (don't use whitespace!) "Applications/Adobe_AsDoc"
- Copy the Flex SDK 2.0.1 into that "Adobe_AsDoc" directory
- Rename the Flex SDK directory to "FlexSDK_201" (which might not be necessary, but I tried to avoid any special characters within the directory names)
Great. So all you have to do now is download and use this ANT build.xml (download):
XML:
-
?>?>?>
-
-
<project default="asdoc" name="Documentation">
-
<property environment="env"></property><!--
-
Markus Raab - derRaab.com / superclass.de
-
This ANT build.xml works on a Mac with a FLEX SDK 2.0.1 in the following location:
-
/Applications/Adobe_AsDoc/FlexSDK_201
-
For more informations see: http://blog.derraab.com/2007/11/23/running-adobe-asdoc-on-my-mac-using-ant/
-
ATTENTION: Use relative paths (according to this build.xml)
-
-->
-
-
<!--
-
ActionScript directory location in source-path and doc-sources (both are needed?)
-
-->
-
-
<property value="../src/as/" name="source-path"></property>
-
<property value="../src/as/" name="doc-sources"></property><!--
-
List with all your used library SWC files (using a directory causes asdoc not to write any documentation files?)
-
-->
-
-
<property value="../src/as/mdm.swc ../src/as/layout.swc" name="library-path"></property><!--
-
Documentation output directory
-
-->
-
-
<property value="./classes" name="output"></property><!--
-
SDK Location (without whitespace!)
-
-->
-
-
<property value="/Applications/Adobe_AsDoc/FlexSDK_201" name="flex-sdk"></property><!--
-
Location of the asdoc templates
-
-->
-
-
<property value="${flex-sdk}/asdoc/templates" name="templates-path"></property><!--
-
run
-
-->
-
<target name="asdoc">
-
<exec executable="${flex-sdk}/bin/asdoc">
-
<arg value="-source-path ${source-path}"></arg>
-
<arg value="-doc-sources ${doc-sources}"></arg>
-
<arg value="-library-path ${library-path}"></arg>
-
<arg value="-output ${output}"></arg>
-
<arg value="-templates-path ${templates-path}"></arg>
-
</exec>
-
</target>
This is one of this quicknotes just for not forgetting a simple issue:While developing a "AS2Wrapper" for embeding AS2 contents in AS3 applications I recognised that _globals within the loaded AS2 SWFs still exist when you unload this SWF and load another. This seems to be quite apparent but I thought about the AVM1 as some kind of sandbox.
Wow again! Drew Cummins recently released a alpha version of his FOAM calles physics engine. You definitely should check it out here. It runs really stable...
This performance test shows how fast the ActionScript AVM2 runs compared to the AVM1, Java(!) and JavaScript: See it
Wow! I found another great Sneak Peek. Imagine you integrate your own skype like service on your website which enables costumers to call you on your cellphone using this little app. Great: Video
Today I found a real interessting Sneak Peak Video about porting C / C++ or other librarys to ActionScript 3. This will make a lot of librarys available to ActionScript 3 without rewriting anything. Thing about different file formats and stuff like that! Great possibilities! Watch the video here.
I really enjoyed Arals talk on the Flashforum Konferenz about SWX this september. And now you can also enjoy it right here. He's a great guy!