Monday, December 31, 2007

Buttons, Symbols, and Filters

I just spent another couple hours of my life tracking down a bug in Flash CS3 that turned out to be... drum roll...

If you put a drop shadow on a symbol that is inside of a Button, the movie will freak out without giving any sort of error messages.

Well, at least it wasn't as bad as Friday's LoaderContext problem. Right now I'm also investigating some bizarre behavior with embedded fonts on dynamic fields, more on that when I know more.

Saturday, December 29, 2007

Favorite ActionScript 3 and Flash 9 Books

I was just writing someone about my favorite ActionScript 3 and Flash 9 books and thought it might be worth elaborating on in the blog. These are not all my AS3 books by any means, but they are my favorites. You may also be interested in these if you're doing Flex development. I do have opinions on Flex books, but that's another blog.
  • ActionScript 3.0 Game Programming University - This may be the most fun way to get your feet wet in AS3 and Flash 9 if you're already experienced with Flash. Especially if you prefer to look at complete examples to learn from. You can also use the numerous examples to build upon instead of starting from scratch. Plus, it is Flash-oriented where many of the ActionScript books are Flash-neutral. The book has great support with an accompanying website with demos of the games you can play, as well as a forum to interact with the author and other readers.
  • Foundation Actionscript 3.0 Animation: Making Things Move! - Another fun and great way to learn AS3 programming. This book is Flash neutral, so you can do it from a text editor with the Flex SDK compiler, FlashDevelop, FlexBuilder, or Flash. While his examples are not complete games like the above, they are small, useful examples. He also gives a good intro to AS3.
  • Essential ActionScript 3.0 - If you plan to write AS3 code, this book is a must to have.
  • Flash CS3 Professional Advanced - This is a great intro to Flash 9 with AS3, probably my favorite all-purpose Flash book, I review it here. This book will effectively bridge your Flash 8 and AS2 knowledge to Flash 9 and AS3. It has very clear explanations and illustrations.

Do you use the LoaderContext class?

Last night I spent several grueling hours trying to track down a bug in an Flash ActionScript 3 program I'm writing. I was getting an error when I would try to call a static method when the movie is loaded into another movie. I wouldn't get the error when I play the movie itself. The error was that the class name is an undeclared variable. Finally, I found a post on that led me to the answer.

The problem was relying on the default LoaderContext parameter to the Loader.load() method. You may not be familiar with this parameter, but it is important in how the Flash Player deals with an additional application being loaded in and how it prevents possible name collisions (see the thread I linked to above).

After solving the problem, I decided to look further into the books I have. Out of six books I looked in, all of them mentioned the Loader class but only one mentioned LoaderContext. Ironically, that was the last one I looked in because it is a Flex book, Programming Flex 2. It has a good explanation of the issues.

Tuesday, December 25, 2007

How I spent my Christmas vacation

It was only a four day weekend this year, but I still managed to slip in some productive fun. Over the weekend I:
  • Wrote my first productive Python script from scratch
  • Created a game in Blender using Blender's game engine
  • Painted in ArtRage (the picture above, you didn't think I was in that did you?)
  • Spent time in Alice
  • Opened a Twitter account
I also did a lot of last minute shopping, visited family, and shoveled snow (lots of snow!). And of course, thanking the Lord for sending his son, Jesus.

Sunday, December 23, 2007

Python and Blender

I was just working on a Blender project where I have 36 objects that I should have set the rigid body property for each. It took several minutes to do manually, was very tedious, and made me realize it was time to learn how to script Blender.

Blender is scriptable through the Python language. I've never scripted Blender and I've never used Python, so it took me a bit... Figuring out the appropriate Blender APIs and then learning the Python syntax (it is very different from what I'm used to like AS3, C# and Java). Here's my tiny, first script:
import Blender

objects = Blender.Object.GetSelected()

for curObj in objects:
curObj.rbFlags = curObj.rbFlags | Blender.Object.RBFlags.RIGIDBODY

Taking it apart, the first line imports the Blender module for the Blender APIs. The second line gets all of the selected objects in a scene using the Object module's GetSelected() method. The third and fourth lines iterate through the list of objects. Line 4 uses the bitwise OR operator to set the RIGIDBODY flag for the current object.

It took me a while to figure this little script out, longer than it took to do the operation manually. But the next time I need to set a property of a large number of objects -- any property, bitwise or otherwise -- it'll take seconds to type instead of minutes in the interface.

Thursday, December 13, 2007

Flash Object Drawing

When I first saw the Flash 8 feature Object Drawing, I thought it was just automatically grouping the object (like with the Group command), so I dismissed it. I dismissed it for a whold version! Last night in Flash CS3 (Flash 9), I turned Object Drawing on for my little boy, and then noticed when he moved the cursor near the edge of the object that the curve on the cursor appeared!

After a quick test I realized that groups were indicated with a bounding box that was closer to a cyan color where the object bounding box was a darker blue. It is very cool that the objects are still modifiable in the standard Flash manner of pulling out curves, corners, or corner points, yet they do not merge with the shape below, it's like having the best of both worlds... being able to use Flash's very natural feeling vector drawing tools, but have the result be modifiable in a way that is more similar to traditional vector tools like Illustrator. I don't see this technique replacing the old Flash way of drawing, but supplementing it so I don't have to rely on moving back and forth between layers so much.

It is easy enough to break apart objects with Ctrl-B, just as you would Symbols or Groups. But how can you make them from a non-object? After cruising through the menus, I was clueless. So I resorted to using the online Help (the equivalent of driving and stopping to ask for directions, IMO). The stop was useful, to make an object select Modify > Combine Objects > Union. Whoo hoo! The only thing that was missing was a shortcut to make a union. Since I don't really using the Group command, it was a quick decision to switch the use of Ctrl-G to make objects instead of groups.

Wednesday, December 05, 2007

Programming Alice 3d

I just downloaded the Alice 3d programming environment Carnegie Mellon University. It is a interesting way to learn programming logic without getting bogged down with dealing with syntax problems. By dragging and dropping you can construct your logic and create stories with 3d characters.

Since I'm back using Blender, I had to see if there was a way to develop 3d models in Blender for Alice. The official site is slim on documentation from a user perspective, so developer documentation is non-existent. In the program, I noticed you can import and .ASE file. I'd never heard of that and didn't see it in the Blender list of export formats. Fortunately, Blender is extensible through Python and someone wrote an import and export script for .ASE.

Just put the exporter script in your Blender scripts folder. I tested it and it works as long as you make sure none of the objects you make sure your object names don't have a "." in them.

Working with Alice set my Java-sense to tingling. I could tell it is a Java app from the look and feel, plus they have all sorts of .JAR files in the application folder. Having spent some time with Java, I started poking around. Knowing Java likes the .JAR format, which is really .ZIP, I renamed an Alice .A2W file with the .ZIP extension instead. Sure enough it popped right open with WinZip. It was very cool to poke around inside. Most of the contents were XML files. It's fun to see how it's put together.

One downside is when I tried to use the "Export Movie" feature and got a "This feature is not implemented yet" dialog box. Why even put the menu item in the menu if it is not implemented? Another problem was when I tried to view it as a web page. It didn't work but there was a link with instructions. Basically, you need to make sure you have Java, Java3d, and the Java Media Framework (which requires a reboot). Those are three separate downloads from three separate pages. Not too user friendly! Lastly, after downloading and installing those, rebooting my machine, I find the applet version does not play back showing the word balloons and opacity changes in my "world". So if you want to show others your work, you'll have to pass around the .A2W file, which is basically the source code and files. Even that has some issues in that supposedly some mail programs recognize that it's really a .ZIP and change the extension. I haven't confirmed that behavior.

Still, Alice is a great tool and it is free. In a short amount of time, my kids were creating short stories using the pre-created characters.

Monday, December 03, 2007

Cleaning up HTML with grep

I came across an email I sent out a few months ago to some co-workers. I thought it would be useful on the blog. I really like grep, but I haven't had the opportunity to use it as much in the last year. These are grep searches in Dreamweaver, it can vary a little from software to software (ie, Vi, Visual Studio, etc has some varying functionality).

I just had to go through a file that had tags with a varying width attribute I needed to whack, ie:

With grep it was a quick search with the following (the grep stuff is in red bold):

Then I had to whack a bunch of opening and closing paragraph tags:

Lastly, there were a slew of span tags, ie:
<span style='font-size:10.0pt;font-family:Arial'>John <span class=SpellE>Nyquist</span></span>

To whack those: