dezza’s blog - utterings from the dezmonator

multipleinstances.png

I have been forever doing repetitive tasks in the Flash IDE. Just recently I had the prospect of giving a lot of items on the stage instance names. In certain situations this might have indicated a missed opportunity to attach and place symbols dynamically. As it happens, the instances were all different symbols and much easier to position visually than with code. I decided to try and write a jsfl script for Flash that would auto name instances on the stage.

What it does:
Takes selected unnamed stage instances and gives them names based on their library symbol name. Multiple instances that use the same symbol will have numbers added to the name to give each instance a unique name.

To run the script, copy the file into the relevant commands folder of your Flash :

Windows Vista

drive\Users\username\Local Settings\Application Data\Adobe\Flash CS4\language\Configuration\Commands

Windows XP
drive\Documents and Settings\user\Local Settings\Application Data\Adobe\Flash CS4\language\Configuration\Commands

Mac OS X
Macintosh HD/Users/userName/Library/Application Support/Adobe/Flash CS4/language/Configuration/Commands

Mac
/Users//Library/Application Support/Adobe/Flash CS4//Configuration/Commands/

The script can then be accessed from the commands menu in the Flash IDE

Download the script
autoname-instancesjsfl.zip

The script explained:

JavaScript:
  1. // dom - the flash DOM
  2. var dom = fl.getDocumentDOM();
  3.  
  4. // hash to keep store whether a base name will be used more than once
  5. var usedNames = new Object();
  6.  
  7. // hash to keep count of how many times a base name has been used during autonaming
  8. var renamedNames = new Object();
  9.  
  10. // total renamed instances count
  11. var renameCount = 0;

Declare some variables. When autonaming I need to know it advance of giving an instance a name whether it will require numbering as well as it's 'base' name and if so what the count for that base name is already. I use some hashes to store that info: the base names as keys with a usage count as the value.

 

JavaScript:
  1. // return true if instance requires rename
  2. function requiresRename( instance ){
  3.     if( (instance.instanceType == "symbol" && instance.symbolType=="movie clip")
  4.         ||  instance.elementType == "text" ){
  5.         return instance.name == "";
  6.     }
  7.     return false
  8. }

This returns whether or not an instance should be auto named. I did a bit of experimentation on what sort of properties items that could have instance names were to generate the appropriate values. I added a clause for textfields as well, but I wasn't able to figure out how to distinguish dynamic text fields from static text fields so the script might not work properly if static text fields are in the selection.

 

JavaScript:
  1. // return true if name is used more than once
  2. function hasMultipleInstancesOfName( name ){
  3.     return usedNames[ name ]> 1;
  4. }

Checks the usedNames hash to see if a base name has been used more than once. I use this later to decide whether or not to auto number instances that share the same base name.

 

JavaScript:
  1. // update a hash with names and usage count
  2. // names as keys and usage count as value
  3. function addToUsedCount( dict, name ){
  4.     if(! dict[ name ] ){
  5.         dict[ name ] = 1;
  6.     } else {
  7.         dict[ name ] ++;
  8.     }   
  9. }

This increments one of the usage count hashes for a name.

 

JavaScript:
  1. // get base name for instance
  2. function getBaseName( instance ){
  3.     // use library item name if possible
  4.     if( instance.instanceType == "symbol"){
  5.         var s = cleanName(instance.libraryItem.name);
  6.         // make first letter lowercase
  7.         var s1 = s.substr(0,1).toLowerCase();
  8.         var s2 = s.length == 1 ? "" : s.substr(1);
  9.         return s1 + s2;
  10.     } else {
  11.         if( instance.elementType == "text" ) return "txt";
  12.         return instance.elementType;
  13.     }
  14. }

This generates base names from the library symbol's name for mcs and just 'txt' for text fields. I also force the first character to be lowercase to follow the convention for instances.

 

JavaScript:
  1. // very basic string clean
  2. function cleanName(name){
  3.     var n =  name.split(" ").join("");
  4.     // remove any path parts before name
  5.     if( n.indexOf("/") != -1 ){
  6.         n = n.substr(n.lastIndexOf("/")+1);
  7.     }
  8.     return n;
  9. }

Simple cleaning of symbol names for use as instance names i.e. remove spaces. I name my symbols reasonably sanely so didn't look for much more that would create invalid instance names, such as symbol names that start with numbers for example. I leave more robust cleaning up to the reader.

 

JavaScript:
  1. // iterate over selection and autoname instances 
  2. if(!dom.selection.length){
  3.     alert("Please select instances(s) to name");
  4. } else {
  5.  
  6.     // first pass to check if any instances names require numbering
  7.     for( var i = 0; i<dom.selection.length; i++){
  8.    
  9.         var instance = dom.selection[i];
  10.    
  11.         if( requiresRename(instance) ){
  12.             var baseName = getBaseName( instance );
  13.             addToUsedCount( usedNames, baseName );
  14.         }
  15.     }
  16.  
  17.     // second pass to rename instances (in reverse to respect selection added order)
  18.     for( var i = dom.selection.length -1; i>= 0 ; i--){
  19.  
  20.         var instance = dom.selection[i];
  21.    
  22.         if( requiresRename( instance ) ){
  23.             var baseName = getBaseName( instance );
  24.        
  25.             if( hasMultipleInstancesOfName( baseName ) ){
  26.                 addToUsedCount( renamedNames, baseName);
  27.                 baseName += "_" + renamedNames[ baseName ];
  28.             }
  29.        
  30.             instance.name = baseName;
  31.        
  32.             renameCount ++;
  33.         }
  34.     }
  35.  
  36.     alert( ""+renameCount+" object(s) renamed");
  37. }

This is main renaming script. It iterates over the selection twice. The first pass essentially decides whether automatically generated names would be used more than once. The second pass than applies the names to the instances, updating the counts as it goes so the auto numbering can be added if required. I found that iterating backwards in the second pass meant that items would be numbered the right way based on selection order.

Finally a little message to display the total rename count.

(2 comments)

So you're working on a Flash project with l-o-t-s of imported bitmaps and you want experiment with various export settings.

Finally in Flash 10 you can edit the export settings for more than one library bitmap at a time. It used to be tedious to say the least adjusting them one by one if you needed to change many.

However if you have Flash 9 ( or 8 ) you can add this extra functionality yourself by creating a custom control using the extendable jsfl api that Adobe products have. I'm sure other people have made things that can do this, but I couldn't really find what I needed, so I decided to make one myself which may be of use to others. Also included is the source fla if you want to see how it works.

bitmappropertiespanel.gif

This video tutorial by Lee Brimelow is a good primer on how to make your own custom Flash panels. If you haven't made one already, it's much easier than you might think.

Instructions: Download the zip and put the enclosed 'Bitmap Properties.swf' file in one of the the following locations:

MAC:

[User]/Library/Application Support/Adobe Flash CS3/[language]/Configuration/WindowSWF

WIN:

C:\Documents and Settings\[User]\Local Settings\Application Data\Adobe\Flash CS3\[language]\Configuration\WindowSWF

After moving the file restart Flash and go to

Window->Other panels->Bitmap Properties

You should now see a panel 'Bitmap Properties' that will let you change the export settings for whatever bitmaps (or folders of bitmaps) are selected in the library in one hit. Enjoy!

Download Source: bitmapproperties.zip

(2 comments)

I really enjoyed my first visit to Brighton, and Flash on the Beach 08. Some peeps at work have asked me what I saw at the conference and if I have any links to share, so I thought I'd post a diary of what I likes. Sorry about the text overload but I didn't take any pictures of the presentations :(

Because of the competing time slots, I didn't get to many of the presenters I would have liked to, apologies go out the speakers worthy of review who aren't mentioned.

Monday

Dr Woohoo
blog.drwoohoo.com
www.inthemod.com
Dr Woohoo demonstrated something I've never seen before: mashing up CS3 applications with 'ExtendScript'; which uses javascript for intercommunication between CS3 apps such as Photoshop, Illustrator and Flash. Calling methods on the DOMs of CS3 apps to do various tricks. Opening custom swfs as panels in Photoshop. Automating the creation of layers and painting in them etc. Crazy stuff. Did you know that you could run a script to paint frames in the video layer in Photoshop? I didn't. Not sure what the true potential of this stuff is but interesting in any case. Also showed some eye candy such as 'The Enraptured Cranberry Jellyfish from Tokyo'.

Andries Odendaal
www.sumona.com
kids.discovery.com/games/whizzball/whizzball.html
http://www.gamegecko.com/beetlebuggin.php
I remember Andries way back in the day when he blew everyone away with his IK (Inverse Kinematics) skeleton. I'm pretty sure that was built in Flash 4 which had the scripting capabilities of a toaster. Andries then showed a progression of his work since which included some stunning 3d Director work, which unfortunately never got published.

Chris Orwig
www.chrisorwig.com
I'm not a photography buff so I had never heard of Chris but was glad to have attended what was a engaging and well delivered presentation. He gave some great insights to budding photographers, reminding us that a good photo comes from avoiding distractions such as equipment and weather conditions but about experiencing life and capturing the moment.

Erik Natzke
jot.eriknatzke.com
play.natzke.com
Erik specializes in a fluid style of generative Flash art resulting in a abstract painterly style chaotic in movement and rich in detail. I find the work pretty chaotic and at times a bit overdone, but they look fantastic when you see them created. Erik also took the audience through his creative process and revealed some of the mechanics behind art.

Inspired session: James Paterson
www.presstube.com
So the inspired session in case you don't know happens in the evening after everyone has taken a break for some dinner, and headed back for a quick beer or two before 8pm. There's a palpable sense of anticipation amongst the crowd for these sessions and James didn't disappoint. Beneath the exterior of what appears to be a pretty casual unassuming guy is the beating heart of a mentalist. Starting from his influences and experiences as a kid right through to recent work, James entertained the crowd thoroughly with his kooky 'gonzo' cartoons.

That was the end of Monday. Everyone headed down to the Audio bar which quickly became completely rammed. Subsidised 1 pound drinks did little to ease the pressure at the bar. Good fun tho, think I got back to the hotel at about 2.

Tuesday

Joa Ebert
www.hobnox.com
blog.joa-ebert.com
The most advanced session I saw, Joa took us through some of the challenges faced and solutions achieved in creating the hobnox audio tool, which I think may be the most technically impressive Flash site in the interworld. It turns out that if you want to provide seamless audio output from an application this complex, you have to do some serious optimisation, and Joa showed us some of the techniques used; Object Pooling, optimised Quad-Tree traversal, and effectively disabling Flash's Garbage Collector by never creating or destroying objects at runtime. He also discussed the Event model they created, which Joa assures us cuts development time considerably.

Jam Session
André Michelle, Carlos Ulloa, Ralph Hauwert, Mario Klingemann, Joa Ebert, Keith Peters)

With only 10 minutes each to speak this was quite an intense session. All the presenters did well given such time slots.

Joa Ebert did 10 minutes of 'live-coding' in his session which started off with some pretty straight forward looking code and descended into some crazy bit shifting that resulted in a swirling particle system of pixels reminiscent of the flocking of birds.

After very trustingly passing his 303 into the crowd to play with André Michelle used his latest version of the hobnox application attempting to recreate a some quintessential german techno track the name of which I can't remember. Techno is probably my least favourite type of electronic music, but it was nevertheless thoroughly enjoyable to see Andre assembling the necessary gadgets to bring it together.

Keith showed some generative line art that started off with simple formulas which over a number of iterations he tweaked to reveal surreal landscapes.

Carlos and Ralph in their respective sessions presented some PaperVision work with Carlos showing the 'in an Absolut world' project (try dragging the blocks to see the underlying collision detection and physics at work) and amongst the things Ralph (I think?) showed was an impressive 3d motion tracking experiment in which he managed to composite a runtime-rendered interactive 3d teapot seamlessly onto a panning video image.

Finally, in the last mini session, Mario used his 10 minutes to show some off the capabilities of the Peacock application he's been working on. With a GUI that looked a bit like Quartz Composer Mario plugged quite a few bits together to ultimately repaint a web cam picture of the other presenters with a bird shaped brush that he'd made by manipulating a picture of his hand.

GMUNK (bradley Grosh)
www.gmunk.com
Bradley went through his background in film, pixel art and flash pieces, before taking us through his more recent projects getting right into his process, which included quite a lot of Maya work for broadcast motion graphics. Some really impressive results.

Inspired Session : Robert Hodgin
www.flight404.com
Robert took us back to a profound moment in his life during which he experienced synæsthesia for the first time which for him meant experiencing sound visually. Kind of makes sense when you see the direction of his work. Quite amazing stuff. Showed a number of processing examples including some recent unpublished work

Hoping to avoid the crush, we went to a quiet pub for a drink after the session finished. Headed down to the chosen venue HoneyClub some time later which at that time was pretty much empty. There were signs around the bar saying "beer is back on" so I guess it had been pretty mental earlier. Went to some other place down the road for more unecessary intoxication before battling against the gale force offshore wind with my late night pizza.

Wednesday

Rob Bateman
www.infiniteturtles.co.uk
Away3D
Robert showed off the latest release of Away3d. The Away3d team have added a number of features recently including improved depth sorting, reduced image distortion, phong-shading (makes objects look smooth and glossy) and surface caching. It looks like the team at Away3d might be concentrating on performance and rendering improvements over the PV3d guys which perhaps are more focussed on making their product accessible to new users. In any case, it's great for the community that there are alternative solutions in this space.

Seb Lee-Delisle
www.pluginmedia.net
blog.papervision3d.org
Seb gave a tutorial style presentation showing how easy it is to get up and running with PaperVision3d. Aimed at users new to PV3D he stepped through a bunch of primer examples that more often than not included a floating cow. I would have liked to see him push the product to it's limits rather than only show simple scenes. Nevertheless it was an entertaining presentation and there were some good tips to improve performance such as 'baking' shading onto models where possible. I was kind of expecting native 3d support in Flash 10 to diminish the need for developer 3d solutions, but it seems like this won't be the case, as the demonstrations of Flash 10's 3d capabilities appeared only to support moving 2d-sprites around in 3d space, as opposed to 3d meshes, lighting, etc.

André Michelle
blog.andre-michelle.com
www.hobnox.com
André talked about his background and some of the factors that had led him to the Hobnox project, before showing how to use the new sound features in Flash 10. He made sure to thank Tinic Uro for the inclusion of the new sound API a response to the 'Adobe - MAKE SOME NOISE' campaign that André et al started. Beginning with the very basics of sound creation, the demonstration started with a basic tone and added processes to show how sound can be generated and controlled in Flash 10.

http://blog.andre-michelle.com/2008/fotb08-sildes-and-sources/

Rob Chiu
www.theronin.co.uk
There's nothing better than sitting back to enjoy a visual feast of motion graphics. Helping Rob present was hecq (Ben Boysen), who has collaborated with Rob with providing audio and sound direction on a number of collaborations. Rob's recent work showed a different more personal direction from is earlier work which was equally well received. Amongst other thing on Rob's site, you can see the FOTB08 movie here.

Mario Klingeman
www.quasimondo.com
a.viary.com/blog/peacock
The start of Mario's presentation was pretty oblique, with him trying to get his computer to recognise a QR code which he held up to his web cam. He had some trouble, something I'm sure to do with the thousands of watts of lighting he was standing under, but soon got underway revealing a process that he had used to get QR recognition working in Flash. Quite a feat given the jumble of pixel data generated from a web cam.

Jonathan Harris
http://number27.org
In the final session Jonathan, talked about his background in painting, entry into computer science, and early experiments in infographics design before showing of his well known 'we feel fine' which by now has collected over 11 million feelings. He then showed other pieces such as 'The whale hunt', 'I want you to want me' and a more recent yet to be published project utilising interviews gathered in Butan. Jonathan finished by making a point that he thought some of the audience might find hard to take, suggesting that the industry, still in it's adolescence, had focussed work on execution at the expense of having a meaningful message as it's core. I think the point was valid, though perhaps made in a somewhat negative way.

(no comment)

We have just deployed the mega-beast at www.playballoonacy.com.
Our game is in your internet suckas.

screenshot of the balloon race

(no comment)

This is the first phase of the latest project I've been working on at Poke, a flash site for Orange www.playballoonacy.com. Finally the big clients are letting us use AS3 (Flash9). This project is massive. Thankfully, I'm getting some help from Gabes aka Pixelbreaker. Get a balloon or submit your site to be part of the race.

(1 comment)

tm_vs_fdt.jpg

I finally made the switch to FDT. My munificent employers stumped up the 599€ for the enterprise version which is a fairly substantial outgoing. Up till recently I have been doing all my AS editing in TextMate, which at €50 is considerably cheaper and in many ways rocks. I love it's straight forward interface and customisable features.

TextMate is flexible. With a bit of help from some eager contributors from the TextMate community I had some really great additions to my workflow. You can publish swfs directly from the TextMate interface using the open source AS2 compiler MTASC (see this post) or Adobe's free MXMLC compiler ( I haven't managed to get it to work with the faster FCSH yet) along with integration with ANT build scripts for fast and easy multi-swf builds (see Simon Gregory's blog for the AS3 bundle and the ANT bundle).

So what does FDT offer? Well as-you-type code checking, and cross referencing of your custom classes for one. Automatic organisation of imports is a massive time saver. Refactoring of classes, methods and properties is also something that is trivially easy in FDT. I seem to be spending a lot less time maintaining the boring stuff and more time concentrated on the 'real' bits of code.

I still miss a few things about textmate, being able to drag any project on to textmate and have it opened in a few seconds. Vertical text selection and editing. In the end the features of FDT are just too powerful to resist. For an Actionscript project, especially if you are working with frameworks or AS3 where there are many packages to remember it saves a lot of time.

Publish AS3 from Textmate

(no comment)

fwa_unlimited.png

The Unlimited website mentioned in this post is up for FWA Site of the Year. If you've got a sec please throw a vote it's way.

(no comment)

jennypackham.jpg

Just finished work on the Jenny Packham site, lots of Flash wizziness which once again benefited from the Pixlib framework. I sort of inherited this project after the original build went a bit haywire. I'm starting to see how a project's complexity increases exponentially when many interactions are possible from anywhere in the application.

Credits:

Project Management: Simon R | Art Direction / Site Design: Buzz, Al | Flash Programming/Build: Dezza, Russ| Back End: Nilesh, Igor

(no comment)

Unlimited web site

This is a project that we just finished at Poke for Orange's 'Good things should never end campaign'. It's an unlimited web page! That's as in unlimited not *unlimited. I'm pretty happy with how it turned out in the end, as the concept of unlimited made me pretty nervous to begin with. This is the second project I've completed using Francis Bourre's open source Pixlib framework for Flash and I must I am loving it. Thanks Francis!

Credits:

Project Management: Alex, Karen | Art Direction / Site Design: Julie, Nik, Nicky | Illustration/Animation: Rex | Flash Programming/Build: Dezza, Dee, Stinky, Matt, Marius | Back End: Knotty, Marc | Sound: Nick

(1 comment)