Flex Seminar Presentation, Flex and Flash, Online

My presentation in New York at the Flex seminar is now online. You don’t have to register, just fill in the info and hit submit. You can download the slides there, or at the bottom of this entry.

I’ve done this presentation 3 times this year, and it has changed a lot in the past 3 months. That was when I started experimenting with getting Flash content to work with Flex, ultimately coming up with the idea for my presentation. I’ve learned some new things since then, talked to some real people already doing this type of work, and refined the communication of the ideas. The most drastic has been my return to the design world via a consulting gig, which has greatly affected my views on the subject. All of my OOP purism and framework obsessions in the past few years in application development and programming has definitely compromised my perception of design. I usually expouse the feature set and thus potential, but usually find myself longing for real, and actual designer participation. The larger projects, the less designer participation. Even worse, the “designers” have been less of what I would call a true designer.

I wasn’t “walking the talk” as it were, and it was quite frustrating. Constrained IT budgets leaves the responsibility up to me to convey value of good design, and thus pitch to my employers the need, from a technical perspective, of why we need budget for an extra team member. I’d say all 3 of my attempts that I can remember failed.

I remember reading a blog posting from a Flash designer on LiveJournal about 8 months ago. I had read his posting on one of the Flash community groups there about how a lot of his former work was getting outsourced. He perceived a lot of the work done as comparable. I’m sure some subjectivity colored his perceptions, but his main point was that he couldn’t compete with the insanely low rates and was extremely frustrated.

I suggested he charge for the creative vision, and long, satisfied client list he would bring to the table. I’m not sure if that advice went anywhere. Not sure if it went anywhere.

My network of design talent is just insanely small. I’d say I have a very valuable network of friends and colleagues that greatly contribute to my success. Only 1 is a professional creative, and 2 can do design services if asked.

That’s pretty pathetic compared to the programming talent I know. It makes it even harder to identify an “A-Team”. Typically, I don’t have to and most clients and potentials ask me about the development talent I know; rarely if ever do their requests vary from that.

That doesn’t help me when I have the opportunity to make a positive impact on a project by recruiting design talent. I need to do another contractor post to garner talent, but I have a feeling I need to get into some different blog aggregators.

Anyway, back to the presentation bashing. First off, in seeing myself speak and answer an audience member’s question, I have failed to effectively communicate what states and transitions are, as well as their value to the various programming and designer camps. I need to work on that.

Second, after talking to some coworkers, I need to do some more compare and contrasts of methodologies. A lot of people don’t recognize all the painful alternate routes one can take when using Flash in Flex, and therefore it is not immediately apparent why my methods are valuable and hard won.

I need to show some of those ways as well as their pros and cons. The tradeoff will be less in depth explanation of what Flex 2 offers with regards to design. I think it greatly adds context but gotta trim the fat somewhere.

One subtle thing that needs to be modified is the attitude. In talking to some individuals, I’ve found the traditional Flash Development workflow used in Application Development doesn’t fly because it’s based on flawed assumptions.

The assumptions were “Designers are not allowed in the FLA. They hand over production art as a prototyped FLA, and the programmer implements.”

This same assumption translates to Flex as “The Designer cannot create usable MXML. They instead should provide, like Flash, a set of comps or even a prototype FLA like before.”

This is flawed logic. One team has successfully had designers create usable MXML that the programmers can later utilize, as-is. That’s huge. Let me say it again in case you missed it. A designer created some MXML that the programmer liked. !!!!!!!

Naturally this is just one company, but it’s a fantastic sign nonetheless. There are plenty of Flash designers that can navigate a programmers FLA and be extremely productive and have a great contribution to the project. However, the pretense was that the FLA was setup, from the start, by a programmer.

This, to me, was WAY more important in Flex because of the way Cairngorm works and the insanely large code-bases on some Flex projects. Having designers navigate package structures seemed like a no win situation. Apparently I’m wrong and glad to be so.

Furthermore, my comments on the Flex design view weren’t agreed with by some. I verbally bashed its representation of my apps. While I did recognize it is a phenomenal improvement over Flex 1.5, I criticized how it’s not entirely there yet and thus shouldn’t be considered an iron clad tool in the designer’s toolbox. Others had contention with this and haven’t experienced the frustrations I have. Apparently the way I structure my MXML either is not the optimal way, or my expectations are too high. Hopefully the latter.

Again, I think I need to trim some of the Flex design context… that or just breeze through those slides quicker. As long as the audience recognizes the capabilities, that’s fine; the actual implementation on some of those things like programmatic skins isn’t really that important.

My original test run was 1 hour and 40 minutes with 20 of that actual Flex Builder 2 and Flash 9 demoing of code. The Flex Seminar one, because of hardware issues, was condensed into 30 minutes. If I speed through some of the Flex CSS and Skinning, I think that will allow more time for IDE showcases of code that really drives the technical points home. I’ve gotten decent feedback, and none negative, on my Flash approach code-wise. Still, I need to finish some more sample code. The examples I’ve shown in the past have been received well when seen in context, but are definitely agency biased vs. typically software shops.

I’ll iron this stuff out by MAX.

Gnash Gives Me Nightmares

Am I the only one in the Flash community scared to death by Gnash? I haven’t been following the OSFlash mailing list in a long time, so haven’t been privy to the public discussions to see the community’s overall stance over time. I’ve only got a snapshot of context.

MTASC did it right. If your code works in the MTASC compiler, it’ll work in the Flash compiler. I currently do not see how Gnash could accomplish the same thing. I have a sinking feeling the fragmentation of the differing feature set will form some instances where a project depends on said features, and thus the code base only works in Gnash. Seriously, who is going to hold the Gnash developers accountable when something works in the Flash Player and not in Gnash? Will they care? Perhaps they instead should market it not as a “Flash Player Player”, but rather an open source Rich Internet Application engine? haXe is pretty successful at this.

If the above becomes a reality, hopefully I’ll get a poison dart frog shot in my neck from Zagar. Fragmentation is cool in Quake rockets, not Flash Players.

Flash Components vs. Flex Components

Been so busy with my current consulting gig up in Detroit, I haven’t had the time to keep hardcore tabs on the community. What I HAVE seen is a good public reaction to the v3 Blaze (Flash 9) components that Grant & Metalliq are working on. Adobe has done well in creating a new market for programmers to create RIA’s via Flex while continuing to enhance its tools for the Flash community. The key point here is 2 communities, aka, 2 markets. It’s getting more blatant every day, but there is still seems to be some unrest regarding why Adobe is creating an entirely new component set for Flash 9 using ActionScript 3 instead of simply just integrating the Flex 2 components.

There are a lot of reasons, the primary being what I just said; 2 markets. To say it another way, 150 – 300k SWF’s don’t fly on public facing, high traffic websites. Many Flash Developers have solved their “should I use Flex for my next project” question by creating a small Flex app, and then seen the resulting SWF file size by using only a few components. “Well, that was easy… *sigh*”.

There is a reason we created our own component set on the current project I’m on, related to the above. The current mx component set has too much extra baggage we don’t need. All the CSS and related styling code is useless. We skin the components via the designs the creatives give us, we don’t setStyle(“color”, 0xFF0000). Those things work wonders in the software development world where design is extremely conservative, the last priority, or not even talked about. Not to mention creatives don’t design with the mx component set in mind.

“A tile list? A box button list? A set of foldable panels interspersed with up-side down ComboBoxes? Um… uh… Flash 8 doesn’t have those, bro… what to do?”

Create ’em. That’s what we did. Instead of the 72k (mx components we would normally use) base set, 12k of that being default component graphics we’d never use, we have a nice 15k. Like Adobe’s plans, ours is made to be lightweight with no-code-needed-skinning the primary engineering goal.

The other reasons would take another blog post. Suffice it to say, the above proves a lot of us still working in the design world cannot utilize the Flex 2 component framework. We CAN still use Flex Builder 2, mind you, to code ActionScript 3; she’s the hotness.

So what to do? Get someone from the Flash community who knows the target demographic, and has previous experience producing a professional set of components for the point of sale. Gee, who do we know that has done that and is qualified? Grant Skinner of mCom, Chafic Kazoun with his phat charting components, Peter Hall with some of his past work as well as working with Aral Balkan on Optimizer, Keith Peters of Bit Components fame, and a few others.

Chafic now has a company and somehow became a fireman (wtf?), Peter is doing his own consulting thang, Aral is doing mad teaching, and Keith is dropping AS3 examples like crazy so I guess he’s contracting. That leaves Grant. I’m sure many other peeps were considered (enFlash, etc.).

Flash Developers don’t need layout engines, CSS, or box models. They need a lightweight, low dependency, and easily skinnable component set for Flash 9. A set that takes advantage of ActionScript 3 speed and bitmap caching, yet eloquently dances around some of the new garbage collector challenges.

Hopefully Grant, Metalliq, and thus Adobe will deliver.

…Even better, hopefully by that time people will stop f’ing paying me to do Flash and instead start paying me to do Flex 2! I’m sure after 6 more months of Flex 2, I’ll just miss Flash again and repeat the endless cycle.

Speaking of grass is greener, some Rabbi in Lucky # Slevin, a gangster movie with Bruce Willis, mentioned how he straddles the fence and thus his entire yard is green. W00t! It was a metaphor spoken in monotone, mind you, but cool nonetheless. That’s why I’ve been promoting using Flex & Flash together, so much so I’ll be uber content when it’s an industry norm.

Modular ActionScript Development

In doing Flash Development for a multi-swf site, we ran into the “first class wins” problem. Basically, an ActionScript class’ bytecode is stored with the SWF that uses it. If the compiler detects a SWF being used, it’ll compile it in. This means, in a website that utilizes multiple SWF’s, 2 SWF’s that utilize the same class will both have their own copy. This is a waste of filesize which costs the user bandwidth.

All classes in Flash Player 8 and below are stored on the _global namespace. This is a special object added in Flash Player 6 that allows the storage of data common to all SWF’s that are loaded in dynamically at runtime, either via loadMovie or loadMovieNum. Before _global, classes were stored on _level0 …usually.

Flash Player 8 and below have a concept of levels. These allow SWF’s to be stacked on top of one another. You could do the same thing with MovieClips stacked on top of one another, but they had to exist in _root. Levels on the other hand each had their own _root. Now, there was a safe way to ensure every SWF was looking at the same data, and a great place to put classes.

No class could be overwritten, however. Classes are basically written in an #ifdef fashion behind the scenes when using ActionScript 2, like so:

// if the class isn't defined"
if ( _global.Ball == undefined)
{
        // define it
        _global.Ball = function(){};
}

Using that code above as a base, you can see how all subsequent loading of SWF’s have their classes of the same name / package ignored. The Flash Player assumes it’s already loaded, and thus does not use the class bytecode in the loaded SWF. On a job I’m on currently, we ran into this problem. We put a trace in our code, and it never ran when we deployed our SWF to the website. That’s because the website was already loading a SWF that had the same class, and thus was ignoring our new one since our SWF loaded later. Again, first class in wins.

This same problem also exhibited itself with loading applications into Central, Macromedia’s early foray in getting SWF applications onto the desktop (pre Apollo). Since Central was a SWF loader of sorts, you’d have classes left defined on _global, like they should be. This caused problems however, when you would load in a new SWF to test and not see your changes. If you didn’t reload Central, or delete your class from _global, it’d stick around, and your newly loaded SWFs would use the old classes.

The way class definitions work with loaded SWFs is not a bug and is by design for a few reasons. Additionally, it has been significantly improved in Flash Player 9.

Paraphrasing Roger’s entry about flash.system.ApplicationDomain, the justifications are basically:

  • A Loader should control what it’s loading
  • Classes not being replaced by loaded SWFs eases security concerns
  • Makes static / Singleton implementations predictable, and work with child content accessing the same classes

There are others, but those are the ones relevant to this discussion concerning Flash Player 8 and below.

You can additionally use this implementation to your advantage. Roger discusses some ways with the pro’s can con’s to each with regards to Flex development. For Flash development, some additional points are a little different.

For example, using Interfaces to allow 2 or more SWFs to talk to each other prevents the same class being included in both SWFs, and thus saving space. This includes all class dependencies, so you can see how this is a great way to encourage the good practice of coding by contracts (using interfaces) with strong-typing, both in ActionScript 2 and 3. This also prevents you from having to go through the laborious process of using Remote Shared Libraries. While RSL’s are great, there are currently no good tools (aside from ANT in Eclipse which Flash doesn’t have) to help management of RSL’s, thus they are a card house. When you get them working, they rock and look great. They are not change friendly; one breeze of scope creep or refactoring, and the whole thing comes crashing down. Hell, if it makes Darron Schall sweat, you know they are hard.

Roger mentions that using implied dependencies via external-library-path isn’t such a good idea because the reverse, having the shell exclude loaded classes, doesn’t work as a use case and is backwards. With context to Flash, I disagree with the first part. I do agree that a shell excluding child classes is silly. Now, interfaces imply you have a good API designed. Our API and designs fluctuate daily. While I agree with Roger that usually your implementation changes, yes, in application development, I’d agree. However, in the Flash world, the shiz is chaos. It may sound like a cop-out, and it is. I refuse to write good code knowing it’ll get torched tomorrow. I’d rather write working code that is maintainable and flexible enough to adjust to change requests. If 20% of what I’ve been writing dies, so be it. In the design world, things change down to the deadline. We also don’t have the kind of time to “flesh out” out our API’s. We can make a great first pass, yes, but when your design can change at a moment’s notice, what’s the point? “Man, this ComboBox is phat! It extends our base TweenComponent, and moves really well in that list. Huh? What do you mean they want the list items to fade in now vs. the list zooming up!? I thought they liked it and signed off on it last week? Son of a LKEJRLKJgfdsjglkdfjg””. That’s not sarcasm; it does happen, a lot. Imagine re-writing an entire list component and all sub-classes… it sucks. Will you now spend the same amount of time hammering out an API… or just make it “good enough”? What if you suddenly have no need for a List in the first place?

Using the exclude.xml functionality built into Flash, having loaded SWF’s exclude classes that the shell will contain for them can work quite well. The trade off is, you need to remember to compile the “framework.swf” every time you make a change to a shared class. That way, all of your child SWF’s that are loaded into the main one use the same class, and are smaller since they don’t have to keep a copy of it.

How do you create & mange this framework FLA without tools like ANT? JSFL – JavaScript for Flash. There are four things you need to do.

First, you need to identify commonly used classes. These are classes, visual components and/or utility classes, that many FLA’s use. You then put these, like so, into a framework.fla on frame 1:

com.company.project.Class;

Notice the lack of import. Flash will recognize that as a usage and compile the class into the SWF. Keep in mind you do not need the MovieClip assets that go with visual components. With Flash Player 8 and below, these cannot be shared in a simplified fashion. Thus, you’re best bet is to externalize your bigger assets like images and sounds so they’ll be downloaded to the internet cache, and other SWF’s can load the same images and sounds. For frameworks like the mx one, it’s kind of a big deal, because the base component framework has a lot of built-in graphic assets that now have to be duplicated in many SWF’s. However, most design frameworks are made to be skinned, and thus are usually just lightweight MovieClips; containing a bounding box, a stop, and maybe more lightweight base classes on their assets layer, so this really isn’t that bad.

The second thing to do is to write a JSFL script that can auto-generate exclude.xml files. These text files that must reside next to your FLA file must also have the name yourfile_exclude.xml where the yourfile is replaced with the name of your FLA file. When you compile your FLA, Flash will look for this file, and if it finds it, it’ll make sure NOT to include any classes listed in the exclude.xml file in the SWF.

What your JSFL file will do is loop through all library items, and if it finds a class that is used the base framework, it’ll make sure to add that class to the list in the exclude.xml.

The downside? You won’t be able to test this SWF locally. That is unacceptable. Therefore, the third thing you need to do is to write another JSFL that deletes the exclude.xml file if there, and then performs a test movie.

Both of the above JSFL files can run in Flash MX 2004 7.2 and Flash 8 which both include the FLfile.dll. This allows JSFL to read and write text fields.

With Flash Player 9, it’s different. It also depends on if you are using the Flex 2 framework or not. Without repeating Roger’s good entry on it, Flash Player 9 has made a new place to manage the different sections where these classes are. The reason for this is because SWFs are no longer always tied to the display. Now, with the DisplayList, classes that represent display objects can exist independently, and need to be managed someplace with relation to, but not being tied to, the DisplayList. There is also a little more control over how these loaded classes are handled, and where they are stored.

When loading a SWF, you can determine which AppDom (pronounced like Kingdom – Roger’s slang for them) the Loader will use when loading the SWF. When the SWF is loaded, the classes are held in that context.

Someone, sometime, is going to have to handle this for ActionScript 3 in an easier way than is done currently with regards to Flash. Not all of us are building Enterprise Applications with SWF. Some of us don’t need the large Flex 2 component framework for our work. We need something lighter weight, like the set that Grant n’ Friends are working on for Flash 9 (Blaze), with less dependencies so it’s easier to modularize classes without the need for interfaces and Remote Shared Libraries.

Again, I agree with Interfaces with regards to Flex 2 apps, but in the design world, we don’t have that kind of time, nor can we garner that kind of commitment to API’s. Until I get a better IDE, I’ll never agree with RSL’s. To be fair, I haven’t given them a hardcore run through in a sizable Flex 2 project yet.

Anyway, I haven’t had time to peruse Roger’s Module source yet, but the “on the fly class loader” sounds pretty hot. It’d certainly make that skins on the fly tons easier via DLL-like SWFs, yes? I hope to write more about this subject in the future when I have some scripts to show as well as example file size savings. Additionally, while some bitch about how it’ll be hard to do this kind of stuff with the Flex 2 framework, SOME of it can be done, enough to make a positive impact I’m sure. When I’m done doing Flash consulting, hopefully I can jump back to some Flex 2! Till then, attach this.