Archive for the ‘AS3’ 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…)

Flash Player 10 - 3D Example

Tuesday, October 21st, 2008

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).

(more…)

KitchenSync version 1.6 released!

Wednesday, October 15th, 2008

KitchenSync version 1.6 is released! Guess what feature it doesn’t have yet… That’s right! There is STILL NO Color Tweening (unless you count ColorMatrixFilter tweens which it does have). However, I hope I can crank out and release version 2.0 over the next two weeks which would have it.

Here are some of the features that 1.6 DOES have:

  • Added a TweenFactory which provides an easy to use interface for creating new tweens including an object parser similar to FuseKit’s interface. You can now use something like:
    var tween:ITween = TweenFactory.newTween({target:foo, properties:"x:0~100, y:500~200", duration:"3seconds", scale:1~5});
  • Altered KSTween to use multiple tween targets. Now includes methods like addTweenTarget(). This allows you to tween multiple properties with a single KSTween object!
  • Added an optimized implementation of IAction called KSSimpleTween. This class showed a 25% performance increase over KSTween!
  • Added SoundTransformTarget for changing volume or panning of a sound.
  • Added new action groups including:
    • KSSimultaneousEndGroup which causes all children to end simultaneously. This is like a parallel group in reverse.
    • KSSteppedSequenceGroup for sequencing PowerPoint-like applications. This automatically pauses the group after each child is completed. Instant slideshow!
  • Finished adding IAction interface. This allows more flexible and customized use of the synchronizer by allowing you to create actions without using the AbstractAction superclass.
  • Also added ITween and ISynchronizerClient interfaces
  • Changed the license from LGPL to MIT license.
  • For a complete list, check out the ChangeLog!

To get the latest version, go to the Google Code project page. Thanks and enjoy!

Flash player 10

Wednesday, October 8th, 2008

Its that time again. Time to get into the latest and greatest tech from one of those giant software engineering companies. This time, the tech is Adobe’s Flash player 10.

Step 1: download the Flex 4 SDK and the Flash player 10 (debug version).

Step 2: Create a fresh config file that will target Flash player 10.

Step 3: Use MXMLC to compile your Actionscript or MXML file.

Step 4: Explore AS3 with Flash 10!

I’ve only tinkered around a bit at this point. But as soon as I get a chance to build a crazy app, I’ll have a more thorough write-up. So far, I’m quite excited at the new features. Be sure to read up on the following:

new Vector class

The inverse kinematics package

The new Shader class

The all new text engine package

ColourLovers API

Tuesday, September 16th, 2008

Colour Lovers API lets you pull color palette information with very Flash-friendly urls and XML results! I dare you to make something with this.

Also, I found this little blog post very interesting.

Announcing the KitchenSync demo contest

Tuesday, September 16th, 2008

Leading up to the debut of KitchenSync 2.0 at the <head> conference this October, I’ve decided to solicit the community for some help with creating AWESOME DEMOS that show off the sequencing library. I’ve also decided to do this in the form of an AWESOME CONTEST! This could be a great opportunity for you as a developer to (a) Try out KitchenSync for the first time (b) Get noticed by other developers around the globe and (c) win FABULOUS PRIZES! Details after the jump!

(more…)

Accessing named MovieClips placed on the stage in Flash CS3 while staying true to OOP best-practices

Thursday, September 11th, 2008

Each developer has a favourite IDE that he or she swears by. I’m an Eclipse man myself. However, during a project I worked on recently, I had the misfortune of diving back into development using Flash CS3, a tool that, despite it’s widespread use, I have managed to mostly stay away from since it’s release. Why? Flash CS3 is a BAD tool for ActionScript development*. Needless to say I was a bit rusty with the Flash authoring tool, but I was nonetheless determined to create a nice, clean, object-oriented, design-patterny product.

*Perhaps I shall elaborate on this statement in a later post

The first thing I did was create some MovieClip symbols. I created, for example, a custom button containing a background (to which i gave the instance name “bg”) and a text field (called “label”). I then opened the properties for this button and included a path to a class (com.foo.MyButton) that would be associated with the symbol. In the class, I declared the two child MovieClips as variables like so.

package com.foo {
   import flash.display.*;
   import flash.text.*;
   class MyButton extends MovieClip {
      public var bg:Sprite;
      public var label:TextField;
   }
}

However, when I ran this code it seemed to choke on the two variable declarations.

Error 1151: Has this ever happened to you? How embarrassing!

Error 1151: Has this ever happened to you? How embarrassing!

I was stumped. Was Flash CS3 actually unable to deal with this situation? Many people I asked seemed to think so. Eventually, I talked to someone who knew the solution.

Sarah Plowright of ActionScriptGirl.com had this advice:

Remember how if you place a MovieClip on the stage or in another MovieClip in an AS2 project you had to also declare a variable of the same name if you’re using a custom class? Well, in Flash CS3 / AS3, Adobe has decided to give us developers some options. The only problem is, they didn’t exactly make these options obvious to the user. If you didn’t know about this change, you  be getting all sorts of nasty errors and wondering why you ever decided to build that project using Flash instead of Flex.

If you’re getting errors along the lines of "1151: A conflict exists with definition myMC in namespace internal." and you’re working custom classes attached to library objects with instances, the error is probably caused by the fact that you have “Automatically declare stage instances” checked. This checkbox is located under Publish Settings > Flash > ActionScript 3.0 Settings. If it’s checked, Flash will automatically add variables to your class at compile time. If you already have tried to declare a variable in your class for this instance, the compiler will throw error 1151, as you will now have two declarations of the same variable. If it’s unchecked, you will have to declare a public variable for every onstage instance that you want access to in ActionScript. Remember, you must make your instance declarations public, or they won’t work!

Make sure that "Automatically Declare Stage Instances" is unchecked.

Make sure that "Automatically declare stage instances" is unchecked.

The fix is easy, simply decide whether or not you want Flash to create your variable names for you. I personally prefer to declare my own stage instances as I believe it’s a better practice to have all your variables listed at the top of a class, but annoyingly, this means I will have to uncheck the “Automatically declare stage instances” checkbox for every new FLA file. Unfortunately, this option only seems to be available under publish settings, and not available under the global application preferences.

Here are some sample files that show’s how this all works.

accessingMovieClipsExample

I happen to agree with Sarah that the best way to work is to uncheck the checkbox and declare all of your variables yourself. This is the only way that really enforces good practices when you are using classes behind your MovieClips in the library.

Thanks for the help, Sarah!

Double Dissapointment

Friday, August 22nd, 2008

ECMA script 4 (or 3.1) and OpenGL 3.

I may be in the (rare?) position of being highly interested in two disparate technologies. The first being an online scripting language standard governed by ECMA (used in Javascript & Actionscript). The second, an open standard for real-time rendering governed by the Khronos Group (OpenGL). In recent days these two languages have faced most unfortunate developments. First the ECMA script 4…

(more…)

Papervision3D Part 3: Features continued

Sunday, August 17th, 2008

This posting is part 3 of a series. If you find that you’d rather start from the beginning, check out Part 1 and Part 2 first. In this post, I’ll cover Papervision animation, the ASCollada project, render statistics, performance optimization.

Animation
Animation in Papervision3D can be performed the exact same way animation would be performed in 2D. Simply apply any tween or algorithm to an object property (like x, y, rotationX, scaleY, etc) and re-render the scene. But, for imported animations its not quite that simple. Lately Moses’s GoASAP package is being adopted in testing for the Papervision engine. It could soon become adopted by the system.

The Collada DAE Parser
Imported animations come in plenty of flavors but must conform to the same system. That’s the reason the animations package exists. Papervision has long supported externally created 3D assets. You’ll find those file parsers in pv3d.objects.parsers. Although, these importers are nice to have, a big part of Great White was the introduction of the open source project ASCollada. ASCollada is an amazing parser for the standard 3D asset interchange format known as Collada. Collada files are basically very dense XML files that use a .dae file extension. Collada files can be exported from Maya, 3D Studio Max, Blender, Google Sketchup, and XSI. However, level of support for those programs probably follows this order: 3D Studio Max, Maya, Blender, Google Sketchup, XSI. Also, if you’re importing MD2 models, the MD2 file parser will import most animations as well.

(more…)

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

Wednesday, July 30th, 2008
  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. (more…)