Wednesday, September 19, 2007

Populating a TextField before it exists

A friend of mine posted the following Flash problem the other day:

I tell a movie clip to go to a frame. I want to put something in text fields on that frame, or set some property of some movie clip on that frame. But if I gotoAndStop, and then on the next line of AS try to set something, I get an error. I need to wait for the frame to start, or the objects on the frame don't exist yet. So I have to put a function call on the frame to call a second function to do the setting later on.

The is quite messy. Surely there has to be a better way.

I came up with the following solution, which I think is fairly elegant. You make a symbol with a TextField in it. Set the symbol to extend from a class which has a public static variable you can set, then when the symbol is instantiated later it uses that class variable in the constructor. This works because the class is loaded when you reference it, it doesn't matter that an instance of the class does not yet exist.

The static variable could be an object so you can better identify what value should be populated. You can get the instance name in the constructor to determine which property of the object in the class variable to use. Here's an example of the class:
package {
import flash.display.MovieClip;
import flash.text.TextField;
public class JRNTextField extends MovieClip{
// should use a getter/setter
public static var mytext:Object = new Object();
public function JRNTextField(){
textInSym.text = JRNTextField.mytext[];

In frame 1:
JRNTextField.mytext.asdf = "hello";
JRNTextField.mytext.qwer = "goodbye";
In frame 2:

Frame 2 has two instances in the timeline of a symbol that extends the JRNTextField class.

The symbol contains a dynamic TextField that is named "textInSym".

The instances on frame 2 are named "asdf" and "qwer". As hoped, they get
populated with "hello" and "goodbye", respectively.

Sunday, September 16, 2007

Painter Perseverance

After getting the previous post (rant) off my chest, I've been thinking about and working with Painter. As I stated in an earlier post, Painter is not Photoshop. Photoshop is a great program. It is very stable and works well for editing photos or even creating art from scratch. While Corel is trying to dip into the huge photography market with Painter's Auto-painting features, it is still a tool for creating from scratch. One of the things that has drawn me back to Painter (pun intended), is that they have with few deviations, maintained their focus on natural media. The Painter toolbox is ideal for illustrators, far more so than Photoshop's.

Today I was working on an illustration where I did some initial work in Illustrator, brought that into Photoshop, then brought it into Painter. I found myself popping back and forth between Photoshop and Painter for different techniques. Painter does not have Photoshop's very handy Layer Effects and when it comes to manipulating pixels, Photoshop is hard to beat. But when I needed to create parts from scratch and work without thinking too technically about layers, channels, masks, etc I find Painter more enjoyable. I love being able to turn the image in Painter to get a better angle to make brush strokes or creating just the right brush to work with for the moment. Little things like having my own easily created brushes palette, or having the brush tracker, make a big difference in the creative workflow, and the color palette (which I think has been around since the beginning) is brilliant.

Corel needs to make Painter more stable. Users shouldn't have to worry about the silent, unexpected crashes, the corruption of workspaces, or the annoyance of redraw errors. It's just too good a program to let such solvable problems tarnish it.

Wednesday, September 12, 2007

Corel Painter Instability

This is only the second time I'm using this blog to rant, normally I like to stay positive. I sent a letter to Corel this morning, Painter's instability really made me mad. It crashes significantly more than my any of the other professional caliber programs I use. My eight-year-old has been interested in Painter and started learning it. He started a painting and spent twenty minutes on it and Painter crashed. He had not saved it and was crushed. I'm a veteran of over 20 years of computer use and I still find it unsettling to lose work. Nothing like your child being affected to really get you going.

This reminds me of some years ago when my daughter was interested in learning 3d. I had been giving Animation:Master another shot, but it was still unstable, it crashed frequently. The company said that there were a variety of things that could cause problems because of all the programs that run in the background in Windows. I liked it enough that I even asked the company what kind of system do they use, I was willing to buy a computer and configure it just for its use. They never gave me a configuration. I remember one person from the company even telling me how Photoshop crashes more than Animation:Master. Photoshop crashing is so rare and in the 17 years I've used it, I've never had it corrupt a file. In the meantime, my daughter decided she didn't like crashing and losing stuff so often and moved on to other programs like Photoshop and Premiere. My boy may end up going the Photoshop route as well.

Now Painter does not crash as much as Animation:Master but it is still a significant problem for a program that is supposed to be a program for professionals. I know my workflow is not pressing CTRL-S every minute or two, especially when I'm drawing or painting (time seems to fly when you're in the "right brain" mode). I'd really like Corel to spend some effort in this direction, I've been able to use Painter more and more lately and I'd like to continue to.

So I get a response from Corel saying I need to call in to deal with this problem. After 20 minutes on hold, someone picks up. The support person has me check my driver version of my tablet (it's up to date). He tells me I should reset Painter completely via %APPDATA%, saying the work environment can become corrupt. I tell him that I have experienced this problem before customizing Painter. I'm told that Painter is stable and that it must be something on my system causing the problem (same thing the Animation:Master folks used to say). I mention to him that I use Painter at work with an entirely different configuration and experience the same behavior. He tells me it must be something I'm doing. I mention that in a Painter class I took other folks were familiar with Painter suddenly quitting. He says there is nothing he can do. I suggest he communicate to engineering or whomever that QA needs to be bumped up a notch.

I use Photoshop, Illustrator, Flash, Dreamweaver, Visual Studio, and more and I don't have these sudden crashes no error message(though Adobe's CS3 Suite was hellish to install, the programs run smoothly). Having programming in a variety of languages on multiple platforms over the years, I have an idea of the complexity involved in a product like Painter, but I also know other companies are able to make solid products. Even something as simple as throwing up a dialog box with some info when there is a fatal error might be helpful.

I like Painter, I'd hate to give up on it. Especially after all the time and money I've spent getting into it over the last year! It is a great tool when it is working. The crashing is the worst, but I've noticed other problems. If I use following commands:
Zoom In
Zoom Out
Zoom To Fit

I get horrible redraw problems. Very frustrating. But.. If I use the Magnifier tool, I don't get the redraw errors. I don't think these problems are new, as I was watching a video where the user was working with a version of Painter from 3 years ago and it show some redrawing problems.

Workspaces are another problem. Apparently they get corrupted often enough that they are the first things tech support wants to whack when you contact them with any problem. While this is an irriation, the crashing is the worst. No... I think writing and then calling about their crashing product only to have them blame your system(s) is the worst. Corel's net promoter score dropped quite a few points in my book today.

Saturday, September 08, 2007

Code-behind and States in Flex 2

I've always liked the .NET way of developing web pages, where you have your code separated from your layout. Someone just referred me to this post on using Flex in a .NET code-behind style (thanks Steve!). It's very similar to .NET, you just extend the Application class and use it in your MXML file.

It is very cool but there's a minor error where the package name is left off the screenshot (though the instructions are correct). One of the comments on the post noted that in order to use states with this approach you needed to make a small change from "mx.states" to "app.states" where "app" is the namespace of your application.

I thought I'd post a version of this approach that included the states issue. I hilited where you need to change "mx" to "app" and where you need to add "app" as the namespace. The shots below are of code done in FlashDevelop 3 (beta 3).

UPDATE: September 14, 2007 1:07 PM I've had additional troubles with using the code-behind and states. I'm afraid for now it's best to hold off on using the approach.

Sunday, September 02, 2007

Drawing Limit on Sprites

I learning something new this weekend. When drawing on a Sprite in ActionScript 3, I assumed you were just drawing on it like you would a graphics port and the result was just changed pixels in memory. Ah, but after some pain (and a SWF freezing at exactly the same time each time I ran it) I found it keeps track of the number of things you've drawn on it.

How many items does it keep track of? The nice computer-y number 65536, aka 2^16 or 0x00FFFF. Before you reach that limit you should call the clear() function of the graphics object of your sprite, ie:;
But now with that past, I've got the beginnings of a nice 2d terrain generator.

Saturday, September 01, 2007

Keyframes, MovieClips and Listeners

In Flash CS3... Say you have a MovieClip instance named "my_mc" on frame 1 and add an event listener and you then create a keyframe in frame 2.

If you move that keyframe in frame 2 to another layer, it no longer has the listener. This action creates a new instance of that symbol

If you move the keyframe in frame 2 to frame 3 and insert a blank keyframe between the two, it no longer has the listener because this action also results in a new symbol instance on frame 3.

If you swap a different symbol, it no longer has the listener (not a surprise).

BUT... If you keep the keyframe in the same layer and don't swap the symbol, the instance still has the event listener. Keyframing on the same layer without breaks retains the same symbol instance.

I suppose not that surprising once I think about it, that by moving the symbol instance to a new layer the result is a different instance of the same symbol. A quick trip through the debugger confirmed this.

MovieClip Identifiers

Here's something interesting I found in Flash CS3 using ActionScript 3. Say you have the following:

Frame 1:

Frame 2:
A MovieClip instance named "my_mc"

The output is:
[object MovieClip]

So Flash assigns the property identifier "my_mc" to the current timeline's instance at the start of the movie, before the actual instance occurs on the stage. Then when it does, that property is populated with a reference to the instance. I assume the identifier is created at compile time.