Archive for June, 2004

Flash FocusManager Hell

June 17, 2004 in Programming,Rants | Comments (0)

I’ve been experiencing a lot of pain working with Flash lately, most recently with the FocusManager object. I posted this article in their unofficial support forums and figured it would be worth replicating here, especially since City of Heroes has got me too busy to update my log much lately. 🙂

Here’s what I wrote:

Here are a few things I learned during my painful experience with the FocusManager…

While the FocusManager appears to be a static class (like Math, for instance), it is not, and you need to use what is apparently an instance on the _root to access it, and it doesn’t have the same case, so:

FocusManager.setFocus(MyField); // Does not work
focusManager.setFocus(MyField); // May work, if your script is on the _root element
_root.focusManager.setFocus(MyField); // Will most likely work if the path to your field is correct

While you might assume that you can use the FocusManager to manage the focus of regular input fields and buttons, this is not the case. You have to use the component classes TextInput and Button from the Flash UI Components set (probably TextArea and such as well, but I haven’t used those yet). This one kept me stuck for a while, until something in one of the examples finally penetrated my skull.

You should remember to set the tab index of the fields you want to manage. Flash will use the z-order (in other words, the creation order) of the objects to determine tab order as long as none of them have a tab index value. If you set one, it will be the only one that gets focus from the manager. You can do this in your code with the .tabindex property of the input text fields and buttons, or you can set it in the GUI. It’s hidden in an unlikely spot, in the Accessibility properties for the component. Open that little dialog and you can click through the components and set it. I’m assuming that if you place a tie, the z-order is the tie-breaker.

Aside from that, it was mainly just discovering the right path to put in to reach the objects. I’m using several forms in my app, with functionality built into a custom class on one of the screens (the rest are just forms or dialogs), requiring this._parent._parent.BaseForm.DoSomething() types of relative paths in the ActionScript editor.

My biggest complaint about this whole FocusManager setup is that it is so silent. It would have saved me a lot of time if, the first time I tried to hand it a regular input text object, it had piped up and said, “I can’t set focus to that! Try a component from the UI Components set!” It wouldn’t have hurt, the first time I tried FocusManager.setFocus(MyField) if it had said, “FocusManager is not a static object – use the focusManager property of _root.”

The problem with Flash is not that the bugs and weird UI and syntax inconveniences and inconsistencies are so awful, it’s just that it’s so damned difficult to figure out where the problem is in the first place. The least they could do is make trace() work from an .swf, since it’s much more useful than the built-in debugger if you’re working on a serious application. The built in debugger is all but useless if you’re building a forms application, and the tricks for breaking into an external script file don’t work well in that instance either. Besides, my app won’t do much in the player, so I need better ways to catch runtime bugs in the hosted environment.

The Flash tool set is great for making toys and ad banners, but for real business application development, it leaves a great deal to be desired. What I wouldn’t give for a strict setting in my script.


My Letter to Macromedia Support

June 11, 2004 in General | Comments (0)

If your support form requires the serial number, why doesn’t the About box let you copy the serial number?

We have a Flash component we are building to replace a pure Javascript graph widget that needs the ability to support modal windows in a way that the web browser will not. You click on a grid to log hours assigned to an activity, and program logic checks the hours, occasionally asking you to fill out a sub form or giving you information or error messages. Flash and its form application seemed like the way to go, so we upgraded our version of Flash to MX Professional 2004.

I’ve been fighting with this for the past 3 or 4 weeks, and I have to admit – Flash, at least with the form application components, is about the most unfriendly, unintuitive, and painful development environment I have ever worked with. I’ll just start my laundry list of rants, because I am absolutely livid at this point.

First off, if you use the application.form components, I can find no syntax that allows the javascript program to talk to the Flash component and move the play head, etc. All attempts fail. I finally had to nest the form app inside a regular Flash movie. The Javascript file talks to the regular swf, which then moves the play head on the form app. I could set values in the form app directly, but they would not display unless the Flash movie was somehow refreshed (for example, if a Javascript alert stole focus for a second, after which the new value would show up), so the script is talking to the swf somehow – it’s just being ignored.

The focus management in Flash is absolutely ridiculous. If I’m typing in the text editor, then I alt-tab off to the web to look something up, when I alt-tab back I certainly expect the focus to still be in the text window I was typing in, *not on the stage.* I don’t know how many times I’ve deleted objects I needed because, although there was still a cursor in the text window, the focus was on the stage, so when I hit backspace I deleted an object. At best I wind up moving objects that were carefully aligned. I have to lock things just to protect myself from this horrible interface oversight. The least you could do is hide the cursor mark when you take the focus away from the editor (the cursor stays, it just stops flashing).

If I build a new MovieClip object in my form app, it will not load by any means, nor will any other movie clip after that. The only trick I have found is to create a graphic, do my tweening, then convert that to a movie clip. This seems to fool Flash and it lets things run. The real problem is that, once you step into this trap, you cannot get out short of reverting… no number of undo’s will make the movie clip into the movie. This is a ridiculous bug that only seems to affect form apps… I can go load the movie clip into a regular Flash movie and it works just fine… it’s the forms that are broken. I ordinarily save quite often – with Flash I put it off until the last possible minute so that I don’t save with one of these heinous bugs active in my file.

This combines well with the occasional trick Flash does when you try to get the time line on the application object. Sometimes it won’t take the focus. You click around, trying to select some form or screen instance in the outline and click on its timeline (this was when I was trying to set a break point – see below), and then Flash GPF’s and takes you work with you because you’r afraid to save it until you know it actually did what it was supposed to.

While it’s nice that you can add data types to variables and catch an occasional type mismatch error, it would sure be nice if Flash did a little more error reporting… like when I try to load a movie clip and it doesn’t work, Flash doesn’t give me any clue that anything is wrong, so I have to take out my shovel and my magnifying glass and write a million print statements to try to find the problem. This is largely because the debugger itself is all but worthless in a form based app. You can’t set up any timeline events to trigger it, unless you spawn them from the shell movie I have loading my form movie. In the dbugger, you have to dig down the piece you want *every single time* because the debugger has no memory whatsoever of what transpired before. It would be best if Flash had a “strict” mode like Perl or VB that would let you know if you used an undeclared value… debugging would be much simpler. It would also be handy if trace() did something in a running movie, not just in the dev environment. My movie interacts heavily with the hosting script… there’s no way to test that in the player.

Your Alert control is all but worthless since it doesn’t steal mouse events from its parent. If you pop an alert on a mouse up event, when you click okay to clear it you get another copy because the the parent got the click again. You have to hand code around it. Why isn’t alert modal? I spent half a day fighting with that, finally building a new form screen to do the job. In another language it would have been as simple as: MessageBox(“Here’s your message”)

That sent me down the path of trying to use createPopUp(). Finally got it where it would pop up a window and load my movie clip, but it would not let me access the values of the movie clip (I’d like to set the message text programmatically) – window.content always traces as undefined. In desparation, I gave up and created a movie clip that contains my hard coded message text. The application loads my window, displays my movie clip, even lets me (gasp) center the window on the form! Success at last!
But wait… that’s in the movie viewer. When you load the movie into a web page, the window appears, but the movie clip doesn’t show up in the window.

Why is it so hard to accomplish something as simple as a confirmation dialog in Flash?

As long as I’m complaining, in order to make our application run standalone and on the web, we have an Asynchronous Pluggable Protocol for Windows that makes our application simulate a web server (we don’t want to force standalone users to run a web server) to serve rendered HTML from XML data. The Online version just uses XML web services to retrieve the output.

While the XML support in Flash seems strong, it refuses to go anywhere near my custom protocol, so short of having it in actual files or stored on a server, I cannot use Flash to access my APP. I have to feed everything into the movie by hand because Flash is too paranoid to let me talk through my custom protocol. If a custom protocol has been installed on a machine maliciously, it was compromised long before your Flash movie tried to run. This bit of “security” is buying me nothing but heartache.

Now, maybe I’m a complete neophyte, newbie, and moron, but it appears that I’m trying to use some advanced features of Flash that just do not work. Maybe they’ll be fixed in this upcoming patch, but in all honesty I am not getting my hopes. I’ve posted some of these issues in forums like Flash Kit and Flashmove, but no one seems to have any input. My sole desire at this point is to get past the issues with this component so I can get to the next thing and never use Flash ever again.

I apologize for ranting. It’s probably more of a catharsis than anything else, since I don’t expect any of this to be fixed or changed – I expect you to tell me to wait for the update, but I’m already way behind schedule because of this, and that’s not due out until next month.

You have my best wishes for turning this into premium development environment. You have a lot of work to do before it’s ready for prime time though.

But it’s great for making ad banners.

Now, if you’ll excuse me, I need to go roll back to yesterday’s version of my SWF because your movie clip bug has broken my application again and, unfortunately, I saved it.


Internet Reality – Virtual Object System

June 7, 2004 in General | Comments (0)

A forum that I frequent since I discovered There and City of Heroes contained a recent conversation about building our own “multiverse” along the lines of those found in Neal Stephenson’s, Tad Williams’s, and William Gibson’s sci-fi novels. The topic emerged after There announced that it was going to be scaling back the consumer product to work on privately funded implementations of their framework, and that no new features would be added – in fact implying that the service might vanish completely (although no announcement of cancellation has been made).

Since there’s no guarantee that There will be around, there has been an exodus of sorts to Linden Labs’s product, Second Life. I tried Second Life and didn’t think much of it (besides, I’m too addicted to City of Heroes to give any time to another game). Others of us have been discussing open environments for a virtual world since Linden, or any publisher, could pull the plug at any time, or change the service agreement, or otherwise make it less pleasurable to be a member. An open environment would put the power in the users hands and possibly even move us into the next phase, a new kind of web.

We’ve been looking at the different platforms available to build upon, since we were clearly not the first folks to have this idea. VOS is the one I’ve looked at the closest so far. I have wanted to be involved in game development and in OSS development, so I’m studying to see if there’s a place where I might fit in.