2.24.2006

BlueDot Safari Hacks

BlueDot is a new social search network, it is fun and useful, check it out at Blue.us.

A quick hack to dot in Safari is to save the stylesheet (http://www.blue.us/css/Authoring.css) to your computer and store it in your custom css for Safari (Preferences > Advanced >Style Sheet).

If you don't want to do it this way, you can make a bookmark like this to open up the Dot from Anywhere form at http://www.blue.us/DotFromAnywhere.aspx. To do this go to Bookmarks > Manage All Bookmarks. Select Bookmarks Bar and then make a new bookmark. Add the javascript code below as the url of the bookmark.

javascript:
{
var dotForm = document.getElementById("retroDotForm");
if (dotForm)
{
dotForm.style.display = "block";
}
}

They don't work together though. Once you add the BlueDot stylesheet to you custom stylesheet it will cause the Dot from Anywhere form to not display properly, so you have to choose your hack carefully.

The hack to reveal the Dot anywhere is slightly better in that you won't be left in the dust with changes to the css used by the website. It might be useful to update your local css file any major updates to the site or when you notice something going wrong.

Hopefully a better solution will be found.

2.19.2006

Flash 8 Preloader

If you are coming across this tutorial I will assume you already what a preloader is and why you use it. I am guessing you want to know the technical details the preloader, so I won't go into detail about what a preloader is. You can search Google for that answer.

I will also admit there are many different ways to write a preloader. For example, you can have multiple scenes, code which counts through 100 frames before advancing to the frame of the media. Even with simple scripting techniques the structure of code can very greatly as well. For example you don't need to use a listener object, just write your listeners as functions. With this said, here is the method that I used.

Step 1 - Make a .swf Movie File


Create a .swf file from your movie. You can do this with Flash, by importing video (File > Import > Import Video), or with 3rd party software, and then exporting it (File > Export > Export Movie). You can test the .swf file by opening it in a web browser.

Step 2 - Make a Flash File to Load your Movie


Here comes the fun part. I set up a new Flash document with 5 layers.



The layers are broken down into the following components

  • Functions - Auxillary actionscript functions

  • Preloader - Actionsript code for the preloader (sets up listener)

  • Movie - Contains the Movie Clip instance where the .swf file is loaded to

  • TraceBox - Contains an HTML text area that debugging statements are printed to

  • LoadText - Contains a dynamic text area that displays percentage of movie that is loaded


The two layers, Functions and TraceBox are only used for debugging purposes and can be removed once the preloader works. Because they are used for debugging, I won't go into detail about them. So the layers we want to focus on are Preloader, Movie and LoadText.

Step 3 - Make a Place for the Movie to Load


First we want to make a place for our Movie to load. To do this we need to make an instance of a Movie Clip. First, let's make a symbol (Ctrl/⌘+F8).



The symbol is now in your library and you can drag it onto a layer in your stage.



Since the movie clip I am loading is of me bouldering, I named the instance 'Bouldering'.



Our movie will load into this Movie Clip instance.

Step 4 - Create a Place to Display Loading Progress


Now Flash has a place to put the movie, but there is still no place to display information about the progress of our movie being loaded. There are many different ways display this information. It could be strictly graphic, or simply just text. Whichever way you choose to do it, you must make change your onLoadProgress function accordingly, see below.

In this simple example I create a piece of dynamic text on the LoadText layer. I set it to '0 %' initially since this is what will be displayed before any part of the file is loaded. I named the instance 'loadText'.

Step 5 - Write the Preloader


The method I used to load a movie was to use the new MovieClipLoader class. To use the MovieClipLoader class you must setup a listener before loading the movie with the loadClip method. The listener simply defines functions that will be called at certain events, for example when the loading is starting or ending. The methods I defined were onLoadStart,onLoadProgress and onLoadComplete. Once I add the listener to the MovieClipLoader I can load the clip. Now that the code has been explained, lets look at it:


var mcl = new MovieClipLoader();
var listener = new Object();

listener.onLoadStart = function (targetClip) {
targetClip._visible = false;
}
listener.onLoadProgress = function (targetClip, loaded, total) {
var percentage = (loaded / total) * 100;
_root.loadText.value = percentage + " %";
}
listener.onLoadComplete = function (targetClip) {
targetClip._visible = true;
}

mcl.addListener(listener);
mcl.loadClip("bouldering.swf", _root.Bouldering);


Now, lets break down the code:


var mcl = new MovieClipLoader();
var listener = new Object();


The code above simply creates a new variable of type MovieClipLoader and a generic object that will define listeners for our Movie Clip. The reason to use an Object to hold our listener functions is so we can create multiple movie clip loaders and make separate listeners for each of them without running into conflicts with function name. Or vice versa we can create multiple loaders and one listener that does something dynamic based on a variable set in the listener object.


listener.onLoadStart = function (targetClip) {
targetClip._visible = false;
}
listener.onLoadProgress = function (targetClip, loaded, total) {
var percentage = (loaded / total) * 100;
_root.loadText.value = percentage + " %";
}
listener.onLoadComplete = function (targetClip) {
targetClip._visible = true;
}


This code creates the listeners for the three events of a movie clip getting loaded, the start event, progress event and the complete event. In reality there are more events, but for this simple example I left out the other events like the error event.

onLoadStart gets called when the movie starts to load. I simple set our movie container to be hidden. The movie container will be revealed in the onLoadComplete method.

The onLoadProgress method is where all of the important work is done. This is the method that allows us to give important feedback about the progress of the movie being loaded. The two arguments loaded and total allow us to calculate a percentage. In this method I simply update the content of my dynamic text area to reflect the current progress of the load. _root.loadText will points to the instance of the dynamic text area created in step 3.


mcl.addListener(listener);
mcl.loadClip("bouldering.swf", _root.Bouldering);


The first line of this code tells Flash that the listeners it is supposed to use when firing events is from the listener object we created. The second line tells flash to load the .swf movie (created in step 1) to be loaded into the Movie Clip instance created in step 3. It is important that argument 2 of loadClip corresponds with the name of the instance created on your stage.

Recap


So each part is relatively simple. The key is to make sure you relate your ActionScript to your Flash file properly through the name of the Movie Clip instance. In this case it was 'Bouldering', but you can change it to whatever you like, as long as it is the same in both places.

Click here to view all the Flash files included.

2.08.2006

Checkerboard!

Rather than do anything productive I thought I would make another image function to use with the scripts i had uploaded earlier. Here is the javascript to make a checkerboard.

Script Your Images in Photoshop CS

Lately I have started to play around with scripting in Photoshop for my computer vision course. Here is something I came up with while working on a take home midterm. We had to describe an image described by an equation. Since our professor said we could write programs I decided to do it in photoshop. There are a total of 3 scripts, each of which I will describe next.

The first script is Document.js. This is simply a library function I created to make creating new documents a little easier. Rather than needing to specify all the arguments for a new image I can give a height and width and I will get a new photoshop document.

The second script is called CreateImage.js. This is the script that does all the work in Photoshop. It creates the new document and then iterates over x and y. At each pixel (x,y) a region of the image is selected and filled in with a color. The color is of type RGBColor and is retured from a function called ColorEquation. This function is passed (in order) x, y, width and height. It is your job to define ColorEquation. The function should create and return a variable of type RGBColor.

The third script is Image.js. This file defines two variables and a function (the least information needed to make an image). The variables are the width and the height. The function is called ColorEquation. This function will be given the current pixel (x,y), width of the image and height of the image. You can use these 4 values to construct a color for the pixel (x,y). The color will be stored and returned in a variable of type RGBColor.

Of course, since all of the source code is here for download, so you can it however you want. If you do make something cool please post a reply with some code. It will be cool to see.