Recently in Flash Category

Congratulations Adobe

| 5 Comments | No TrackBacks

A long time ago, I ranted about how development tools for Flash were terrible. I set up a pitch that Adobe just knocked out of the park.

With the Flex Builder 2 IDE, the Flash Platform finally has the killer coding environment that developers from other languages have come to expect. Not only can you use it for Flex development, but you can also create ActionScript projects and use the Flex Builder IDE to drive the code for your .fla files for Flash 9 as well.

As awesome as Flex Builder 2 is, I think the biggest congratulations are in order for the paradigm shift that we just saw. To draw developers to the Flash Platform, Adobe is giving away the keys to the kingdom. For the first time ever, you can develop for the Flash Platform for FREE via an SDK released and supported by Adobe.

The Flex 2 SDK will allow you to use ActionScript 3 and the Flex Framework through a command line compiler to target Flash Player 9. This is a strategy that Microsoft has employed so well -- give away the basic tools for free, get developers to target your platform, and charge a modest fee for a great IDE that makes you more productive as a developer. Finally there is a zero cost of entry for the Flash Platform, which is just what what it needs to grow the developer base.

Kudos Adobe, and congratulations to all of the individuals who made this release possible. Flex 2, ActionScript 3, and Flash Player 9 is, in my mind, the most significant release ever for the Flash Platform. Thanks for the hard work.. I've never had this much fun being a FlashCoder before.

I was looking for an Iterator implementation in ActionScript 3 to avoid reinventing the wheel for the umpteenth time but couldn't find one on Google, so I whipped one up quick that you can download here. This should save someone a full 3 minutes of work in the future....

Usage is pretty simple and straightforward. The download includes the Iterator interface as well as a simple implementation of ArrayIterator for iterating over an array of elements:

import com.darronschall.util.*;

var arr:Array = [1, 2, 3];
var it:Iterator = new ArrayIterator( arr );
while ( it.hasNext() )
{
	trace( it.next() );  // 1, 2, 3
}
		
var it2:Iterator = new ArrayIterator( null );
trace( it2.hasNext() ); // false

You can use this code without restriction under the MIT License.

Tags: , , ,

My FITC 2006 ActionScript 3 Slides

| 7 Comments | 3 TrackBacks

I've posted the slides for my ActionScript 3 presentation for FITC 2006. Did you catch the big announcement at the end?

I had a really enjoyable time presenting this session. It was definitely one of the more technical sessions at the conference, but everyone seemed genuinely interested and I had numerous people come talk to me afterwards (which is usually a good sign).

You can download my slides here. Some of the session highlights...:

  • I dissected the ByteArray class.
  • I created a drawing program that allowed you to either save a JPG or PNG by converting the pixel data into a ByteArray.
  • I covered using URLLoader and URLStream to pull binary information into the player. I demonstrated parsing an Excel .xls file and displaying the results in a DataGrid (holy !@#). My good friend Jim Cheng contributed the Excel-parsing code.
  • I talked about the binary Socket class as well as the types of applications that can be built on top of it. I demonstrated my VNC project and connected to my SuSE Linux server through Flash running in FireFox.
  • I talked about the new Loader display object and showed how to create an on-screen image out of a ByteArray.
  • Lastly, I talked a bit about emulators, and showed the Chip8 Emulator in action.

I also touched on combining Socket and Loader to deliver .swfs in a secure manner. When you view a .swf file, it ends up in your browser's cache and can usually be decompiled rather effortlessly with tools like ASV. I talked about the use case where you can use Loader to download an entire .swf file over a Socket connection (receiving the data as a ByteArray), then place the .swf on the stage via Loader.loadBytes. This route prevents the .swf from being cached by the browser and makes it much harder to decompile. It's not 100% secure yet, but imagine public/private key encryption to deliver the .swf contents over a secure Socket instead. The days of easily-decompiled .swf files may be coming to an end?

Finally, the biggest news and probably most exciting part of my presentation was the very last slide. I made a big announcement - something that I've been dieing to talk about for a very long time now, but was just waiting for the right time.

There is now an Open Source Commodore 64 Emulator written in ActionScript 3! (The Trac page might still be password protected, go bug Aral to remove the password if he hasn't yet.) Claus Wahlers and I have teamed up to create the emulator. It's still a work in progress, and we're looking for hardware-nerds to step up to the plate and help us finish it. The CPU code is complete, but hasn't been extensively tested. The memory code is a work in progress, and we haven't had a chance to start on the display code yet. Still though, it's a good start.

At this point, we're just running the CPU as fast as possible without trying to get the timing completely accurate. On the debug Flash Player, it runs at ~2.5 MHz. On the release Flash Player, it runs at closer to 6 or 7 MHz. This is a good thing, as the original Commodore chip only runs at 1 MHz. So, in theory, it should be possible to emulate the games in real-time without any slow down or speed delays (holy @#!@).

To friends, old and new, here's to next year. FITC rocked the llama pretty hardcore this year. It was great catching up and meeting some new faces, and I hope to see you all again soon!

One last thing - I totally thought way too much about my "supermarket item" that appeared next to my session information. I picked "Love Bites" since my session was about "bytes" and by the end I was hoping you would "love" them. Get it? Hah! Total geek humor... *waits for the tomatoes to fly*

, , , , , ,

FITC away!

| No Comments | No TrackBacks

I'm headed out the door, departing for FITC 2006. This year I'll be giving 2 sessions. The first is a Q & A session on the Next Generation Flash Platform at 9:00 am tomorrow morning, and the second is an ActionScript 3 presentation on Sunday at 10:15.

If you see me walking around, stop and say hi. I'm looking forward to catching up with some old friends that I haven't seen in awhile (like Ted and Chafic), and making some new ones along the way.

Here's to safe travels for everyone attending, and another killer conference this year!

Tags: , ,

Google uses OSFlash

| 8 Comments | No TrackBacks

A few quick news items to point out:

Normally I wouldn't report about a new Google application, but this one is special. They're using Flash to create a highly interactive chart that blends well with AJAX. More importantly, Google used the Flash JavaScript Integration Kit to get Flash communicating with JavaScript.

Rock on OSFlash! I'm waiting for the day for Google to submit their own open source Flash project.... but, just knowing that Google is using open source Flash code makes me smile.

Oh, I turned 25 yesterday too. Go me!

ActionScript 3 JSON Library Now Available

| 4 Comments | No TrackBacks

I'm happy to announce that my JSON library has been made publicly available through labs. JSON stands for "JavaScript Object Notation" and is a lightweight data exchange format, sort of like WDDX on a diet.

You can download the JSON library as part of the core ActionScript 3 library.

Usage is as follows:

// import the JSON library from the core serialization package
import com.macromedia.serialization.json.JSON;

// Encode a native ActionScript object as a JSON string
var jsonString:String = JSON.encode( someValue );

// Decode a JSON string into a native ActionScript object
var value:* = JSON.decode( jsonString ); 

If you run into any problems with it, let me know. It passed all of the unit tests, but there's always a chance that a test case is missing and there's a hidden bug somewhere. I'm interested in hearing any feedback you may have!

Tags: , , , , , ,

Both E4X and Regular Expressions are powerful on their own, but by combining them you can really do some amazing stuff - especially in relation to data filtering...

Manish Jethani outlined data filtering with E4X, but I just wanted to expand on that and show a technique I've been using that combines E4X Predicate Filtering with Regular Expressions.

Consider the following code snippet:

I see this question a lot: "How can I select nodes that contain a certain attribute using E4X? I keep getting a reference error saying the variable doesn't exist..." The answer is to use the hasOwnProperty method in predicate filtering.

The hasOwnProperty method checks to see if a string property name is present, and returns a boolean value. By using "@" as the first character in the property name, hasOwnProperty will check to see if an XML object has a particular attribute.

Using hasOwnProperty instead of just looking for "@hex == " something or other will avoid the error ReferenceError: Error #1065: Variable @hex is not defined on the nodes that don't have the hex attribute. This is because the predicate filtering loops over all of the nodes in the previous XMLList to try to match the expression, and if @hex doesn't exist on the current node being inspected, the error is generated. Switching to hasOwnProperty will gracefully handle the "not found" cases.

The code below shows hasOwnProperty in action, using predicate filtering to select specific nodes.

// Create an XML object that contains two types of color nodes:
// One type with a hex attribute, and another with red, green
// and blue attributes.
var colors:XML = <colors>
		<color hex="0xFF0000" />
		<color hex="0x00FF00" />
		<color hex="0x0000FF" />
		<color red="255" green="0" blue="0" />
		<color red="0" green="255" blue="0" />
		<color red="0" green="0" blue="255" />
	</colors>;

// Use the hasOwnProperty method in predicate filtering
// to find the nodes that have a certain attribute - hasOwnProperty
// will return true if the hex attribute (denoted via @) is found
// on the node.
var colorsWithHexAttribute:XMLList = colors.color.( hasOwnProperty( "@hex" ) );

// Outputs:
// <color hex="0xFF0000"/>
// <color hex="0x00FF00"/>
// <color hex="0x0000FF"/>
trace( colorsWithHexAttribute );
			
// By looking for a false result of hasOwnProperty we can successfully
// select all of the nodes that do NOT contain the hex attribute
var colorsWithoutHexAttribute:XMLList = colors.color.( hasOwnProperty( "@hex" ) == false );
			
// Outputs:
// <color red="255" green="0" blue="0"/>
// <color red="0" green="255" blue="0"/>
// <color red="0" green="0" blue="255"/>
trace( colorsWithoutHexAttribute );

Unfortunately, due to a compiler bug the above code will not compile in strict compilation mode. You'll need to turn off the strict flag if you want to use this code in the current beta of Flex 2.

To turn off strict compilation mode, open the project properties (Select properties from the Project menu on the menu bar). Select ActionScript compiler on the left, and uncheck the "enable compile-time type checking" option.

I much prefer to compile with strict mode on, but to use this approach it's a necessary evil to leave it off. I can say for certain that there's a bug logged already for this. I'm hoping it gets fixed soon!

Tags: , , ,

More Proof that Unit Testing is Good

| 6 Comments | No TrackBacks

I thought I'd share a positive experience I had today with unit testing.

If you don't know what unit testing is, essentially it's an automated process used to ensure that your code actually does what you think it does. It's a fundamental rule of extreme programming, has an active cult following, and has spawned test-driven development.

Without getting into an essay on the background of unit testing, how it's useful, or how to set it up with Flash or Flex, I just wanted to relay my experience this afternoon.

Someone had contacted me about a possible bug in a piece of software that I wrote. Naturally, I assumed this was nonsense (after all, who writes buggy code anyway?). It turns out there was an edge case that I never thought would occur and it was causing erroneous results. I was given the steps to consistently reproduce the problem, and immediately went to work.

There's a reason that you shouldn't rely on undocumented features. The for..in loop's behavior has changed from ActionScript 2 to ActionScript 3. It's a subtle change, but it might break your code.

The for..in loop iterates over the properties of an object. In previous versions of ActionScript, the for..in loop was known to iterate over the properties backwards, in a predictable order. It has been said many times that the order is not guaranteed, but in practice it was always the same, and predictable.

For example, the following code creates an object in ActionScript 2, adds some properties to the object, and then iterates over the properties with for..in. The order of the trace output is always the same:

var o:Object = new Object();
o.prop1 = 1;
o.prop2 = 2;
o.prop3 = 3;
o.prop4 = "four";

for ( var i:String in o ) {
	trace( i + ":" + o[i] );	
}

/* Always Displays:
prop4:four
prop3:3
prop2:2
prop1:1
*/

As an aside, in this type of situation I'd build the object with an object literal (using { prop1:1, prop2:2 ..etc.. }) instead of adding properties like the preceding code block, but the code was written this way for clarity. You can cleary see that the last item added is always the first one found by the for..in loop.

Because the order was always the same, you may have tried to use this to your advantage. However, in ActionScript 3 the same code does not produce the same results. The order of for..in is no longer predictable:

var o:Object = new Object();
o.prop1 = 1;
o.prop2 = 2;
o.prop3 = 3;
o.prop4 = "four";

for ( var i:String in o ) {
	trace( i + ":" + o[i] );	
}

/* Displays:
prop2:2
prop4:four
prop1:1
prop3:3
*/

/* Or, could Display:
prop3:3
prop2:2
prop1:1
prop4:four
*/

As you can see, if you used the undocumented feature of the for..in loop iterating backwards through an object, your code will not work the same in ActionScript 3. This demonstrates another good reason why undocumented features should be used with caution, as future versions are free to change functionality without warning.



About this Archive

This page is an archive of recent entries in the Flash category.

ColdFusion is the previous category.

Flex is the next category.

Find recent content on the main index or look in the archives to find all content.

Archives

OpenID accepted here Learn more about OpenID
Powered by Movable Type 5.02