Filed under Lab

The quest for the elusive “N-gleton”

by

Sure, we’ve all heard of Singleton, the design pattern that limits the number of instances of a class to one. It’s a feel good pattern because it’s easy to use and make us feel smarter in front of our co-workers, even though some would argue that Singletons are just glorified global variables. But for a long time, I have wondered if it would be possible to use the same idea to limit the number of instances to two or more instead of just one. I called this hypothetical pattern an “N-gleton”, pronounced “en-gull-ton”. (UPDATE: Comments from readers inform me that this is called a “Multiton“) It may not be possible to make a poly-instance singleton, it may not be good programming practices, I’m not even sure I can think of a reason why it might be useful, but today, I tried my hand at inventing it and found something else entirely.

Continue reading

AS3 number to hex converter

by

I’ve been working on some code for converting colors lately and getting quite into bitwise operations. In one of the demos I was making, I needed a quick and easy way to see the results of a color calculation. Of course, simply tracing a number, even if it’s in the format 0xFF, will result in a digital number string “255″. I’ve always been a little stumped about how to do this calculation but I realized that it’s actually very easy to do with the & and >>> bitwise operators.


getNumberAsHexString(255); // 0xFF
getNumberAsHexString(0xABCDEF); // 0xABCDEF
getNumberAsHexString(0x00FFCC); // 0xFFCC
getNumberAsHexString(0x00FFCC, 6); // 0x00FFCC - Uses 6 as a minimum number of hexits

I’ve added the code to the AS3lib as  as a global function. I may move it to a utility class later on. You can view the source on Google Code.

Incidentally, in a moment of bug-fixing frustration, I found this article on O.C.A.S. which describes how the same functionality is already built into the toString() method! However, the work isn’t completely wasted since my version includes the option to show leading zeroes and adds “0x” at the front of the result.

Tagged , , , , , ,

Flash Player 10 – 3D Example

by

I’ve tinkered a bit with Flash Player 10. One thing that seems almost funny about the 3D effects of Flash thus far is that very few examples show off actually 3D objects. Most examples I’ve examined show 2D planes transformed in 3D space. So, I’ve created a sample 3D cube primitive in AS3 as a convenient example for people who want to get started with their own parsers or drawing tools (etc).

Continue reading

Tagged ,

20 reasons to use KitchenSync for animation and sequencing on your next project

by

  1. Versatility – Great for tweening animation, yes, but also great for calling functions, disptaching events, playing sounds, controlling MovieClips, and more. Virtually any code can be run at a specific time. In KitchenSync, any event or behaviour that can be sequenced is called an “action“.
  2. Advanced sequencing – There are several types of action groups designed to meet the real-world sequencing needs of projects.
  3. Interchangeable groups – Treats all actions, including groups of actions (like sequences), as the same type of object so they can be interchanged. That means you can nest sequences inside of other sequences.
  4. Video-like controls – All actions, even groups, have the ability to play, pause, stop, reset, play backwards, loop, and jump to a specific time. Calling one of these functions on a group affects all of the items in the group.
  5. Beyond Penner – All the familiar easing functions are included as well as several original ones like oscillators. An easing utility class has also been added which allows you to create hybrid easing functions.
  6. Continue reading

Tagged

Tweening timeline animations with KitchenSync

by

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.

Continue reading

Tagged