Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c03/h01/mnt/55667/domains/blog.michaeljbowen.com/html/wp-settings.php on line 472

Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c03/h01/mnt/55667/domains/blog.michaeljbowen.com/html/wp-settings.php on line 487

Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c03/h01/mnt/55667/domains/blog.michaeljbowen.com/html/wp-settings.php on line 494

Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c03/h01/mnt/55667/domains/blog.michaeljbowen.com/html/wp-settings.php on line 530

Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c03/h01/mnt/55667/domains/blog.michaeljbowen.com/html/wp-includes/cache.php on line 103

Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c03/h01/mnt/55667/domains/blog.michaeljbowen.com/html/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c03/h01/mnt/55667/domains/blog.michaeljbowen.com/html/wp-includes/theme.php on line 623
michaeljbowen.com

Flash CS4 Bug: Kill the Compiler With One Line of Code

January 6th, 2009

I just found a nasty little bug in Flash CS4.  One line of code will result in a project that compiles with no errors and yet no trace statements work either.

Simply put the following line of code anywhere in your project (including in any class, or on any frame on the time line):

1
var version:Number = 0.0.1;

That’s it!  Your project will (seem to) compile with no errors.
You won’t get any trace output either.

Imagine burying this line of code in a random class in a project that has hundreds of classes.  How could anyone find it?

I’m Tellin’ Y’all It’s a Sabotage.

Bugs, Flash

Modules in Flash

December 22nd, 2008

Modules are SWF files that can be loaded by an application but cannot run indepedently.  Modules are built in to Flex 3, but it takes a bit of finagling to use modules in Flash.

I have been able to use modules successfully in Flash.  Below are the steps to follow.  I have also included the sample source code:
http://michaeljbowen.com/examples/modulesInFlash.zip

Step 1
Grab the latest Flex SDK.  I used 3.2:
http://www.adobe.com/products/flex/flexdownloads/

Step 2
In the Flash IDE (I’m using CS4), create a reference to the Flex SDK:
File > Publish Settings > Flash > Settings > Library Path
Add a reference to frameworks\libs (see the following image)

Advanced ActionScript 3.0 Settings

Advanced ActionScript 3.0 Settings


Step 3:

Create a module by creating a class that extends mx.modules.ModuleBase.

1
2
3
4
5
6
7
8
9
10
11
12
13
import mx.modules.ModuleBase;
...
public class ModuleAlpha extends ModuleBase implements IModuleAlpha
{
   public function ModuleAlpha()
   {
      trace("ModuleAlpha created.");
   }
   public function addNumbers(a:Number, b:Number):Number
   {
      return a + b;
   }
}

Step 4:
Compile the module using the mxmlc command line compiler.
Note: If you’ve placed your source in subdirectories, you will need to let the compiler know your source path.
In my example, ModuleAlpha.as is located in the com.electrotank.modules package.
Thus, here is my command to compile:

1
>mxmlc "-source-path+=../../../" ModuleBeta.as

Step 5:
Create a “parent” application that will load in your module(s) via mx.modules.ModuleManager.
Here is an excerpt from the sample code provided:

1
2
3
4
5
6
private const URL_MOD_ALPHA:String    = "ModuleAlpha.swf";
...
_modules[URL_MOD_ALPHA] = ModuleManager.getModule(URL_MOD_ALPHA);
IModuleInfo(_modules[URL_MOD_ALPHA]).addEventListener(ModuleEvent.READY, onModReady);
IModuleInfo(_modules[URL_MOD_ALPHA]).addEventListener(ModuleEvent.ERROR, onModError);
IModuleInfo(_modules[URL_MOD_ALPHA]).load();

Step 6:
Create an instance of your newly uploaded module using the factory of IModuleInfo:

1
2
var modAlpha:IModuleAlpha = IModuleAlpha(IModuleInfo(_modules[URL_MOD_ALPHA]).factory.create());
trace(modAlpha.addNumbers(2, 3));

Done
That’s it!
Be sure to use your powers only for good and not evil.

Flash, Hacks

Flash 10 Speed Test: copyPixel vs. Scrolling Sprite vs. Scrolling MovieClip

November 29th, 2008

When Flash introduced the copyPixel operation a few versions ago, I was very excited.  Finally, I could create blazing fast games that worked more like “real” games instead of using MovieClips.  However, copyPixel is no magic bullet.

Here are the results of a simple test where I scroll a background image.  I guessed that copyPixel would yield the fastest results, but I was wrong.

Note that during initial testing it was difficult to get a big difference with an 800×600 drawing area.
Of course, that’s because I’m only moving 1 image around as opposed to hundreds as in an actual game.

Thus, to make the differences stand way out, I increased the drawing area to 1880×1024.
This will fill up Fire Fox if your resolution is 1920×1200, but you can still see the drawing area.

The frame rate is set to 120.
Note also that I am using a crazy big image of size 4095×4095 (3.5 Megs).

Various OSs and Browsers

# Method Mode Fps Fire Fox - Win Fps Internet Explorer - Win Fps Fire Fox - Mac
1 Copy Pixel opaque 21-23 36-38 36-37
2 Copy Pixel window 40-42 43-45 36-36
3 Copy Pixel direct 54-56 46-48 30-31
4 Copy Pixel gpu 27-28   (wtf?) 43-45 21-22
5 Sprite opaque 24-25 36-37 36-37
6 Sprite window 58-60 62-64 36-37
7 Sprite direct 80-84 58-60 35-36
8 Sprite gpu 120 solid  (wow) 61-63 33
9 MovieClip opaque 24-25 38-40 36-38
10 MovieClip window 58-60 55-62 36-37
11 MovieClip direct 80-83 58-60 36
12 MovieClip gpu 120 solid  (wow) 58-62 33

So, the really confusing thing for me is that copy pixel seems to drag down gpu mode!

Also, remember when “opaque” used to be the best wmode option for performance? Not any more (at least for this specific test).

Flash, Performance

Flex 3 Profiler Bug

August 18th, 2008

I am running Flex 3 on Windows Vista.  For some reason, attempting to profile an application would always fail.  There were no errors or warnings… the app would launch in my browser and simply run without profiling.

The following work around worked for me:

  1. In Flex 3, click on Window > Preferences…
  2. In the Preferences window, choose Flex > Profiler > Connections
  3. Set the Port number to something other than 9999.  10001 worked for me.

That’s it!

Profiler Preferences Window

Profiler Preferences Window

Bugs, Flex 3 ,