Back in late October of last year I started up a new website called ActionSnippet.com. I created the site because I really enjoy reading code - I often skip all the paragraphs in a blog post and just go straight for the code. A new code snippet is posted daily on ActionSnippet.com, usually with a brief description.
I would have linked to ActionSnippet.com sooner but I wasn't sure what direction the site would go in, so I wanted to give it some time to evolve before linking to it. After approximately 260 code snippet posts I can safely say there is much more useful/educational code on ActionSnippet.com than there is weird useless experimental code.
In this post I'd like to highlight a handful of useful snippets for everyday projects and I'll link to a few advanced graphical snippets. If you just want to dig right in, you can look at the all posts page which is just a list of every code snippet on the site.
As you read each of the following descriptions, consider opening Flash, pasting the code into timeline script and testing the swf.
FileReference.save()
-
var file:FileReference = new FileReference();
-
stage.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
-
function onClick(evt:MouseEvent):void {
-
file.save("some text.\nsome more text", "actionsnippet.txt");
-
}
This is one of my favorite features of Flash 10. We can save any kind of file to a user's computer using the FileReference.save() method. Its first argument is for the data to put in the file. This can be a String, ByteArray, or XML object. The second argument is the name of the file.
If you paste this code in your timeline all you need to do is click the stage and you'll get a dialogue asking where you would like to save the file "actionsnippet.txt".


(19 votes, average: 4.16 out of 5) 