Welcome to Mediasparkles

News : Flash

I'm leaving for Germany later today and won't be back until December 17th. I may not have anything to report while I'm over there, but we'll see. I might install a trial version of Flash on my parents' computer to show them that yes, my name does appear in the credits. They might like that. But other than that... see you on the 17th!

 posted by Vera Fleischer (12/6/2003 12:04:34 PM);




When I was working at the University of Virginia, I once created this little demonstration of entropy, a quantitative measure of disorder. It consisted of a sentence whose letters were dispersed randomly (disorder) with entropy and then put back in order with negentropy. The random disorder and systematic re-order of the letters of the sentence was easy.

The hard part was preparing a movie clip for every single character in the sentence. The sentence consisted of 153 characters. Since I was always trying to achieve minimum file size and maximum flexibility, I didn't want to just break apart the sentence and turn each static character into a movie clip. I wanted to only use one movie clip with a dynamic text field inside and use it over and over again. The problem with that is that each letter has a different width, and if you don't know that width, you don't really know where to place each movie clip. So I created a guide layer with a static text field with the entire sentence in it. For each character in the sentence, I then put an instance of the "letter" movie clip in another layer on the stage, temporarily changed the dynamic text field inside to the value of the character I was positioning, aligned it with the corresponding character in the guide sentence, named the movie clip instance, then moved on to the next character. Yes, it took forever. Yes, it was a big pain in the butt.

Two years later - enter the JSAPI. I studied Keith Peters' Waving Text extension and realized that I could use very similar JSFL code to accomplish in a few seconds today what must have taken me several hours two years ago. Here is the code of the JSFL command:


my_doc = fl.getDocumentDOM();
my_doc.selectAll();
my_doc.breakApart();
var my_frame = my_doc.getTimeline().layers[0].frames[0];
var elems = my_frame.elements;
for(var i=0;i < elems.length;i++){
my_doc.selectNone();
my_doc.selection = [elems[i]];
my_doc.convertToSymbol("movie clip", "", "center");
my_doc.selection[0].name = "c" + i;
}

It breaks apart any string of text (153 characters takes a few seconds but succeeds), turns each character into a movie clip and gives it an instance name. The only drawback is that you end up with 153 movie clips in your library, each containing a static text field, but for the time savings I'd be willing to accept the minuscule increase in file size.

The moral of the story: Where was the JSAPI when I needed it two years ago?

 posted by Vera Fleischer (11/30/2003 10:11:10 PM);