Most of us have seen tutorials on how to use Adobe Photoshop to create a tilt-shift effect by using a selection mask and a lens blur. I thought I’d try to reproduce the effect using AS3.
First off, a demo (
) for the people who want to see if this is even worth the time to read.
View source is enabled, if you want the code. The top slider controls the size of the focus area, the second slider controls the location of the focus area, and the checkbox controls whether or not to boost the saturation (because really bright colors look more fake).
Now that you’ve played with it, I’ll begin explaining what’s going on in the code.
Read the rest of this entry »
A buddy of mine asked me the other day how to flip all of the forward slashes in a file path to backslashes using string replace() method in AS3. He said he couldn’t find the answer anywhere online, so I guess I’ll put it here so it will hopefully help someone.
var path:String = "/top/deeper/keep/going/"; var pattern:RegExp = /(\/)/g; var fixed:String = path.replace(pattern, "\\");
If you care to read an explanation of what’s going on, here we go.
Line 1: This is our string that we want to fix.
Line 2: This is our regex pattern that will grab the forward slashes. I think the part about this that may have been difficult is that you have to wrap your escaped forward slash in parentheses, or ActionScript thinks you’re trying to start a comment when you close your pattern with the next forward slash. The ‘g’ means that we want this pattern to be applied globally when we use it, and not just on the first match.
Line 3: This is where we use the pattern to find and replace all of the forward slashes with backslashes (escaped, of course).
That’s it. Pretty simple once you know how.