Archive for the ‘Tutorial’ Category

Tip: Adding version checking to your external code library

Friday, October 24th, 2008

Since version 1.0 of a code library that I’m sure you’re tired of me talking about came out, I have been making steady updates, some of which break legacy code. I was also having trouble keeping track of which version of the library a particular demo was written for. In order to make sure that the new code library doesn’t cause unpredictable results for the old implementations I added a version check to the main class.

This version check is very simple. It checks a version number in the client code against a version number of the library (or external classes) when the main class of the library is initialized. It is also completely optional (so average users don’t need to mark up their code with version numbers).

Here’s an example:

Say you normally initialize your library using:

MyLibrary.initialize();

Which calls the initialize method:

public static function initialize():void {
   // initialize library here
}

If the external code changes unexpectedly (say through an SVN update) this could cause problems that are difficult to trace. The solution is to modify the initializer to match the client code version with the initializer version.

public static const VERSION:String = "1.6";
public static function initialize(versionCheck:String = VERSION):void {
   if (versionCheck != VERSION) {
       throw new Error ("The version check failed! This library is version " + VERSION + ". Update your code or GTFO!");
   }
   // initialize library here
}

And when you run the initializer, use the version number you’re expecting.

MyLibrary.initialize("1.6");

Some things to notice with this approach:

  • I used a string instead of a number for the version number so that it would allow for sub-sub version numbers and other markers, e.g. “1.6.24 beta r545″
  • Because there is a default value for versionCheck in the initializer, providing a version number is optional. Using MyLibrary.initialize() will still work and throw no errors.
  • Unfortunately, there is not much you can do if the version numbers don’t match except to warn the client that the external code has changed. Still, I’ve found this to be very useful.

The code for my initializer in its entirety after the jump…
(more…)

Protip - Making an email forward look like it was sent for the first time

Friday, September 19th, 2008

Has this ever happened to you?

You’re having an awesome birthday bash and you send out an email to all your closest friends… that is, all your closest friends except ‘Ed’. Now you’re faced with the embarrassing situation of having to invite your friend Ed post-invitum. But don’t fret, here’s a simple solution that will save you loads of embarrassment!

Go from Go from this... to ...to this!

Step 1. Find the original email

Did you send a copy to yourself? Good! If not, check your sent folder. Not there? Ask your mom to forward the invite back to you.

Step 2. Forward to yourself and BCC your friend.

Click on the forward button. This time send it to yourself! In the BCC field put the name of the person (or people) you forgot. BCC stands for “blind carbon copy” and the names on this list won’t be listed so they’ll ony see your name listed.

Step 3. Delete “fwd:” from the subject line.

That’s a dead giveaway that you’re a loser and a fuck-up who doesn’t care about his friends.

Step 4. Remove the quote formatting.

You know the blue line that runs down the left side of the text that you’re forwarding? That’s the quote formatting. It may also appear as a “>” or some other symbol. Taking that stuff out is the last step in making your email look fresh.

If you’re using Mac Mail, just highlight the quoted text and press Command + Option + ‘ (apostrophe) until the blue line disappears.

Also make sure you remove the text that says “Begin forwarded message:”! Duh!

Step 5. Make sure it looks right and send!

If done properly, your email will look exactly like a brand new email and your friend will never know that you don’t really like them that much!

Tweening timeline animations with KitchenSync

Tuesday, July 8th, 2008

One of the new features in KitchenSync 1.5 is the ability to tween animations on a MovieClip’s timeline… and I’m not just talking about gotoAndPlay(), I’m talking about controlling the starting and stopping points, speed, and easing functions of an animation on the timeline with code. It does this by incrementally controlling the current frame number of the MovieClip using a KSTween and a special ITweenTarget (a class used to control the values of an object) called TimelineController.

Take this FLA animation.

MovieClip animation

As you can see, there is a simple animation using a guide layer and labels on the key frames.

(more…)

Technique: Semaphores

Thursday, June 19th, 2008

For the past year(!) or so I’ve had a series of articles I meant to write about some intermediate programming concepts that can allow you to write code at a higher level. I regret that it’s taken so long to come around to them, but I hope they can be of some use. This series will cover semaphores, asynchronous tokens, and green threads, and I may extend it with some brief notes on assertions and iterators. Today I’d like to talk about semaphores.

(more…)

Introduction to Flex Resource Bundles

Friday, May 9th, 2008

Hark, Flex developers. Lend me your ears! I must take this post to implore you: use Resource Bundles! Trust me, I know, there’s a lot to keep up with these days, but if you aren’t already privy to the awesome secrets of the humble bundle, hopefully I can help convince you to use them. I’ll show you how, without breaking one bead of sweat from your brow! First, let me tell you why they’re cool. Then, I’ll show you how to get rolling with your first bundle. Then, I’ll set you loose, and hopefully you can all write in with excellent questions and help me make this a great resource for the next readers! Read on, fair Flexer.
(more…)

KitchenSync News: Patch released v1.0.1, source files for Flash CS3, more docs

Friday, February 8th, 2008

kitchenSync

Hey KS Fans,

KitchenSync version 1.0.1 was released last week. This version is just a patch that fixes a few minor issues. Here’s the change log for this version.


===== v1.0.1 (2008.02.04) ======
Fixed Cubic.easeOut bug.
Made getters for Tween's toValue and fromValue.
Added source code to main download.
Added metadata for events.
Updated docs and added summaries to all wiki pages.

I received some feedback from people who were having trouble setting up KitchenSync for use with Flash CS3. I didn’t know this before but you cannot use .swc files compiled with the Flex SDK in a .fla file (WTF, Adobe!) Also, some people were confused by having to use SVN to get the source. To help solve these problems, I’ve added the latest source code as its own download.

I’ve also written EVEN MORE documentation including help for downloading and setting up the source code.

Finally, if you’re using KS, drop me a line or post to the mailing list. I’d love to hear any feedback you may have!

The State pattern in Flex - combining view states with logical states

Wednesday, January 23rd, 2008

If you’ve used Flex, you’ve no doubt (er, hopefully) been using View States (AKA <mx:State>) to change the look of your RIA as it progresses through different situations of use. While this is immeasurably useful, it does not necessarily qualify as an implementation of the State Design Pattern which allows you to change not only how a component looks but how it functions as well.
(for more on design patterns, read my favorite book Head first design patterns).
(more…)

No children on the stage - a confusing Flash CS3 display list issue

Tuesday, January 15th, 2008

A reader wrote to me with an interesting Flash CS3 problem that had me stumped at first (mostly because I use FlexBuilder instead of Flash). I thought I’d post the answer here so we can all benefit from it.

The Problem

Ben H. writes…

I’ve been trying to get familiar with a “best practice” on [looping through the display list]. The trouble is, when I enter the following on the first frame of a blank .fla file:

trace("Number of Children in a blank SWF:"+stage.numChildren);
trace("Child 1:" + stage.getChildAt(0));

I get this:

Number of Children in a blank SWF:1
Child 1:[object MainTimeline]

Now that may seem grand, but I’ve drawn several shapes and have a text field and named movieclip instances on stage as well – so why [does it only count one child?]

Solution after the jump.
(more…)

Pimp my ‘clipse - a list of must-have Eclipse plug-ins for Flex/Flash Development

Monday, December 17th, 2007

Eclipse Rims

FlexBuilder may have its ups and downs but it still remains my pick for best AS3/MXML editor on the market (with TextMate not far behind). Part of the beauty of FlexBuilder is that it’s built on the Eclipse SDK, one of the most versatile and powerful IDEs available, which is not only free and open source, but boasts a wealth of third party plug-ins for every kind of (mostly Java) development. This article will take a look at some must-have plug-ins for doing Flex development as well as some tips for tricking out your development process.

As with all of our entries, your feedback, suggestions, corrections and additions are all more than welcome.

(more…)

Preventing Out-of-memory errors in Eclipse / FlexBuilder

Wednesday, December 5th, 2007

You may occasionally get an error that Eclipse has run out of memory. Part of the problem here is that Eclipse is only allocated 256MB of RAM by default. I’ve found this can be helped (but I sometimes still have problems) when I set my maximum memory allocation to a larger value such as 1024MB. Detailed instructions for how to do this can be found on the Eclipse help site.

If you like playing with runtime arguments like memory allocation, don’t stop there. Check the list of command line arguments on the help page listed above. I use -nosplash which prevents the eclipse logo from coming up during startup. Cleaning the Eclipse application with -clean can be useful too especially after installing plugins or when things are breaking for no reason. (Mac users can skip the tedious .ini editing process and do this by typing /Applications/eclipse/eclipse -clean in the terminal.