December 2005 Archives

ActionScript 3 Solitaire - Klondike

| 12 Comments | No TrackBacks

Here's a little game I've been working on - Solitaire (Klondike) - written using an ActionScript3-only project in FlexBuilder 2.

ActionScript 3 Solitaire (requires Flash Player 8.5 to view).

I'm not entirely sure what I want to do with this code yet. I think I'll be placing it inside of IFBIN but it doesn't really belong in Flex By Example since it's not a Flex project. Additionally, it's not really a Flash project because Flash doesn't have ActionScript 3 support yet so at the moment it doesn't really belong in Flash By Example. I think what I might do is create a Flex 2 shell for the game with a classic menubar and an options panel to configure scoring, deal 1 vs. deal 3 and the card/deck skin, and then add the whole thing into Flex By Example.

This is a great example to use as a starting point for other card games going forward. I've created a generic card engine that is completely skinnable and can easily be extended to create other games (such as FreeCell, Poker, etc). The game features a modular Object-Oriented architecture, so the core card engine can easily be dropped into a game and function without issue. Creating FreeCell from this example is just a matter of changing the game rules since everything else can be re-used.

This is also a good example of using the new DisplayList API. Whenever you drag some cards around, there's no need to worry about depth management or attaching and removing MovieClips to achieve the effect (things we had to worry about with ActionScript 2). Instead, just re-parent the cards and magically they're on top of everything. When the cards are dropped, re-parent the cards again, and magically they're attached elsewhere. I'm really diggin' the new DisplayList.

There are still some things not done - for instance, there's no scoring, and there's no super-cool end game animation sequence (or even a message that tells you you win). However, the game is fully playable, and capable of wasting hours of your life at a time if you let it.

Enjoy!

NeoSwiff 1.x now available

| 1 Comment | No TrackBacks

NeoSwiff has been silently making progress the past few months. They're finally out of beta and have an official release available.

To quote GlobFX:

We are pleased to announce the availability of NeoSwiff for order. NeoSwiff 1.x for Visual Studio .NET 2003 is priced US $595, EUR 525.

Additionally, NeoSwiff Express, a small, free, unsupported IDE
is also available.

Learn more on NeoSwiff 1.x at http://www.globfx.com/products/neoswiff/

Related to this announcement, NeoSwiff Build #5290 has been released.
Read Release Notes at http://www.globfx.com/forums/viewforum.php?f=5

Priced at $595, it's a little bit cheaper than I originally thought it would be. The target market isn't Flash Developers really, but more for C# developers looking to bring their WinForms applications to the web. I've used the NeoSwiff plugin for Visual Studio, and I've really been impressed with the quality of the editor. It's pretty powerful with all of the features that you would expect. Plus, it gives .NET developers a chance to use the same language (C#) for both client and server while targeting the ubiquitous Flash Platform for maximum exposure on the web.

Of important note to those who'd just like to play with the technology - there's a free express edition IDE. It's a stand alone IDE that isn't as powerful as the Visual Studio plugin but it gives you a chance to explore the NeoSwiff SDK and see what it's like to code Flash in C#.

Also, in my experience the WinForms compatibility is spot on. Even though there isn't a visual designer in the NeoSwiff plugin, you can create a C# project in Visual Studio and design your forms visually. Then, you copy and paste the code into a NeoSwiff project and have your form appear in Flash exactly how you laid it out in the designer. It's a pretty cool workflow, and an added bonus is that the layout/resize code is already handled for you.

If you hadn't had a chance to use NeoSwiff yet, download it and take a look at the samples to see some of what can be accomplished. GlobFX has really done a great job, and I'm sure it will continue to improve over time as well. Congrats guys!

ActionScript 3's new loop

| 2 Comments | No TrackBacks

Did you know ActionScript 3 introduced a new loop construct? I discovered this while doing a lot of XML manipulation with E4X, and it's really a gem.

Along with the "for..in" loop, we now have at our disposal a "for each..in" loop. The two loops are very similar in style/syntax, but there's a subtle difference. Consider the following code snippet:

var arr:Array = ["test", "test2", "test3"];
			
// Use a regular for in loop to access the properties in arr
for ( var i in arr ) {
	trace( i );	
}
			
// Use the new for each in loop to access the values in arr
for each ( var s:String in arr ) {
	trace( s );	
}

The first loop will trace values 0, 1, and 2. The for..in loop will loop over the property names in an object - in this case, we get the array indexes. In order to get the values in the array, we would have to "trace( arr[i] )".

The second loop will trace values test, test2, and test3. Notice the subtle difference here? Instead of getting the properties in an object, we get the property values. This is a handy shortcut, and is especially useful in dealing with XML in the E4X manner:

<var data:XML = <model>
		<foo>12</foo>
		<foo>61</foo>
		<foo>hello</foo>
	</model>;
					
for each ( var f:XML in data.foo ) {
	trace( f );	
}

The above loop will out 12, 61, and hello.

Nothing earth shattering really, just something new to add to your bag of tricks... Enjoy!

Flex.org - The Directory for Flex

Archives