Brain Dump

It seems like there are certain things I've learned, forgotten, and been forced to relearn. Rather than write it down somewhere private, or pretending that I have a better memory than I actually do, I thought it might be helpful to put this stuff up on a webpage, and maybe it might get indexed by a search engine somewhere so that others might benefit from my struggles.

Update:

I haven’t looked at, or updated this in years! I have no idea if this all still works...

(Please make sure that JavaScript is active to properly view this page)

jQuery: Make an accordion index (like this one)

I'm starting to learn jQuery, so I figured that this page would be an ideal candidate for experimentation.

First, link to the online copy of the library in the head of your document.

You could also put a copy of the library on your site, by the way...

...and here's the jQuery script that also should be put in the head of your document:

After Effects: Fade layer in with expressions

I just had to do this today; an animation where you basically have a long line of layers spread out in Z-Space (offset from each other by 2000 pixels), being dragged by the camera using a common null. I wanted them to fade in gracefully, but not have to keyframe each one (and move the keyframes as the timing changed).

Add this expression to the opacity of each layer you'd like to fade in:

This expression assumes a couple of things. First, it assumes that there's a camera in the composition named "Camera 1." Secondly it assumes that there's a null in the scene named "Null 2." The values for startFade and endFade are tweakable to your needs.

What it does is subtract the z-distance of the camera's position from the layer's z-position (using the null's position plus the offset distance) to determine the value d. As d goes from startFade to endFade the values are faded from 0 to 100, fading it in.

Want to fade it out? Just swap the values, making the last line:

linear(d,startFade,endFade,100,0)

This was largely adapted from another script by Dan Ebberts, someone much brighter than I am.

Flash preloader with still frame

Let's say you want to load a Flash file, but it'll take a while to load, and you'd like to use a still frame of the first frame to occupy the space on the page until the movie has fully loaded. Here's what I've used in the past:

Make a preloader... call it preLoader.fla (or whatever). This is the file that is embedded in the webpage.

Make 2 layers. Name the first "actions" and the second "still" (naming is optional).

On frame 1, layer 2, put your standby still graphic (that will be replaced when the movie loads).

and voilà!

Be sure to test the actual swf, not using the preview function in Flash, which doesn't always accurately represent what will happen in a browser.

After Effects scripted type substitution

What if you have an After Effects comp that flies 2 words into screen, and then suddenly you're asked to do the same thing for 50 pairs of words? You could duplicate the comp and then tediously enter all the type, or you could be smart and use After Effects scripting.

This AfterEffects script takes a text file with words in it, sticks the words in the appropriate text layer, and makes then make comps from the input, and sets them up to render. The input file should be formatted to be easily imported into an array this example uses commas between word pairs separated by newlines (basically a comma separated file, like those exported from a spreadsheet or a database).

Here’s the script:

// determine the currently selected object in the Project window
var curItem=app.project.activeItem;
// check to make sure it's a comp
if (curItem instanceof CompItem){
// If so, do main function
doIt();
} else {
// if none were selected, advise them
alert("Please select a comp as the active item and run the script again");
}
// main function
function doIt(){
// Open input file
inputFile= fileGetDialog("Please pick the input file!","");

Here’s the HTML:

Index of topics on this page:

JavaScript to obscure email addresses

You don't want to leave email addresses out in the open in websites, unless you want a buncha spam emails promoting penis growth. A good alternative is to obscure the address enough that spambots won't be able to parse it easily. A human being could read the individual address if they tried, but this will break it up enough to confuse most ’bots out there...

// assign the "at" sign to a variable
var atsign = "@";
// assign the name of your domain to a variable for convienience
var here = "xyz.com";
// here's the function that gets called in the code
function mailLink(name,isp,link){
document.write ("" + link + "");
}
// here's how it's inserted into the HTML:

Cycle through IMG elements and assign mouse events, using JavaScript

This could work for other elements, and I believe it to be cross-platform happy. In this case, there are a series of images inside of a DIV named “pictures” that I want to have mouseover events assigned to.

This function would be called in an onLoad handler, like in a <body> tag.

How to shut off remote machines from your developmental website

Say you’re messing with some PHP/MySQL stuff on your test machine, which is connected to the internet, and you want to stop anyone outside from having access to your webserver. The easiest thing is to edit your httpd.conf file (found in /private/etc/httpd/ for you OSXers...) to only listen to your localhost machine, thusly:

(search for this section)
# BindAddress: You can support virtual hosts with this option. This directive
# is used to tell the server which IP address to listen to. It can either
# contain "*", an IP address, or a fully qualified Internet domain name.
# See also the and Listen directives.
#
BindAddress localhost

How to fill a JavaScript array, and then loop through it

(JavaScript part)
(HTML part)
// Make a form element that is filled by the array

Select one of them:

Here it is in action:

Select one of them:

How to display HTML in an HTML document

Use the tags. Yes, I know it's "depreciated," but it works (unlike

).

Here it is in action:

Select one of them:

Picking a random item from a JavaScript array

(JavaScript part)
// Make an array containing some items
function pickOne () {
var phrase = new Array(
"This is the first phrase.",
"Here's another.",
"Another random phrase from a JavaScript script.",
"Wha' chu talking about Willis?",
"This is, what... the fifth phrase?",
"I'm running out of things to add to this list",
"This should be enough to test it."
)
// This next line will pick a random number from 1 to the
// number of phrases in the array... pretty clever, I think...
var randNum = Math.floor(Math.random()*phrase.length);
// This pops up an alert, picking a random phrase...
alert (phrase[randNum]);
}
(HTML part)
// Make a form element that is filled by the array

Here it is in action:

Extracting items from a webarchive

Navigate to the directory where the archive(s) exist.
and type in terminal:
textutil -convert html