Thursday, September 9, 2010

Automatic Text Color Selection in Flash 8


Below is some code that I wrote that will automatically select the best text color based on it’s background. I know the word “best” is subjective, so I really should say it will have the best contrast. This accomplished using color matrices and Quasimondo’s great ColorMatrix class. It basically sets the text color to same as the background, then inverts the color, and finally, desaturates the color. The problem is that it starts to get muddy when you get to a middle tone. To fix this I added a contrast property that when set to 100, always produces either black or white. You can lower this property to see the whole range of grays. In the example below you can click on the color picker to set a new background color. As you move around you should see the text changing. The class code is below as well.

[as]import com.quasimondo.geom.*;
import flash.filters.*;
import flash.geom.*;

class AutoTextColor {
private var backClip:MovieClip;
private var textClip:MovieClip;
private var cm:ColorMatrix;
private var trans:Transform;
private var ct:ColorTransform;
private var contrast:Number;

function AutoTextColor(bc:MovieClip, tc:MovieClip) {
ct = new ColorTransform();
trans = new Transform(bc);
contrast = 100;
backClip = bc;
backClip.cacheAsBitmap = true;
textClip = tc;
textClip.cacheAsBitmap = true;
}

public function setContrastLevel(con:Number):Void {
contrast = con;
}

public function setBackColor(col:Number):Void {
ct.rgb = col;
trans.colorTransform = ct;
cm = new ColorMatrix();
cm.colorize(ct.rgb,1);
cm.invert();
cm.desaturate();
cm.adjustContrast(contrast,contrast,contrast);
textClip.filters = [new ColorMatrixFilter(cm.matrix)];
}

}[/as]

Flash Needs 3D to Compete with WPF


It’s a sad statement to have to make, but it’s true. Since I’ve started learning WPF for work, I’ve been pretty impressed with the features, especially the 3D support. A non-programmer can easily create and manipulate 3D objects as well as project live data or even video onto those surfaces. The actual 3D geometry isn’t anti-aliased so it is pretty jagged, but using 2.5 D like we have in After Effects, is flawless. This is something that Flash is going to have to support because I envision every company wanting their product represented as a 3D object that can be manipulated in all directions. But at the very least, we need to have After Effects 2.5 D control.
Below is one of the test examples I made over at theWPFBlog.com. It consists of a 3D rectangle that has video playing on one side, and has a bio, photo, and timecode readout on the other. The timecode is dynamically being updated on the 3D surface. There is also a 3D progress bar, which is also a 3D rectangle, which adjusts itself based on the video playhead. You can also click and drag to rotate the panel in 3D space. You can right-click and drag to scale it up or down.
Click on the photo below to check it out. You will need IE 7 and the WinFX runtimes installed to view it.
You can do it Adobe!

Flash and WPF – My thoughts so far


So as you probably know from my earlier posts, I am learning WPF since we are using it on some projects. I’ve been playing with it for about 3 weeks now and have come to some thoughts about its potential and whether it has the potential to “kill” Flash. Bear in mind that I’m very new to WPF, so I’m sure that there are a lot of pieces that I am still missing or confused on. The easiest way to do it is to just go through some common features and talk about how they stack up with each other.
Video Capabilities
Well on this one, Adobe has nothing to worry about. With Flash 8 and the new On2 codec, Flash has obliterated the competition when it comes to web video. Not only is the quality superb, but it’s now easy for anyone to add video to webpages and online applications. That coupled with the excellent Netstream API, which allows for 100% customization over the video experience, makes Flash the clear winner. WPF has some great potential when it comes to things like mapping video onto 3D surfaces, but that is going to get really old, really soon. The MediaElement class is pretty bare in comparison to the Actionscript video classes. There are probably other classes in the massive .NET library that allow for more control over video, but Microsoft needs to make them more accessible.

Audio Capabilities
Here is another area that Flash dominates. This is domination is only going to strengthen once the

1
<a href="http://livedocs.macromedia.com/labs/1/flex20beta3/langref/flash/media/SoundMixer.html#computeSpectrum()">SoundMixer.computeSpectrum() </a>
method hits the streets with Actionscript 3. Playing music is pretty much the same thing as playing video in WPF. The MediaElement class is very weak when it comes to audio control and doesn’t let you get access to any spectrum information to create audio-driven animations. I have found out that there are some DirectX APIs that allow you to do this kind of stuff, but it’s pretty heavy stuff that will keep it out of the hands of most interactive designers who only have intermediate programming skills. Again, props to Adobe on the new audio support. We’ve all been waiting for this! No more AE to Flash manual workflows.
3D Support
Here is another one-sided affair, but this one is owned by Microsoft. WPF has some truly amazing 3D capabilities, as seen in this North Face demo put together by Fluid. The 3D engine takes advantage of the graphics card through OpenGL. Whether these capabilities can be realized cross-platform is the real question here. But 3D support shouldn’t be shrugged off as eye candy because there are all kinds of applications for using 3D on the web. 3D data plotting and bar charts that update dynamically have a big impact compared to their 2D counterparts. The 3D support in WPF is excellent, and even better, it’s easy to use. Look for online 3D games in WPF to be a huge area. I’ve said it before and I’ll say it again, Flash needs some level of 3D support in the future to stay on top. Just look at how many developers fake 3D in Flash everyday.

The Programming Environment
Well the good news for Flash developers is that C#, which is the language of choice for coding WPF, is very similar to Actionscript 2, and is even more similar to Actionscript 3. C# requires you to adhere to a more strict style of programming, but this will actually help you to become a better AS programmer. One major difference between the two apps is that WPF is actually closer to Flex than to Flash. WPF applications are created using XAML, which is an XML-based markup language similar to the MXML that’s inside Flex. You then use C# as your code-behind language to handle events or to create custom interactions. You can build your whole app entirely in C# without touching XAML, which leads to some confusion about what should be done with what. Coming from Actionscript, I have felt much more comfortable coding in C# and not touching XAML unless I absolutely have to. I guess this comes from the fact that there is a lot of stuff in Flash that we have to code from scratch. Basically, if you are a competent AS programmer, then you’ll have no problems programming WPF.

Data Binding
This is one are where WPF and the Expression IDE are clearly on the right track. You can choose any property on any object and bind it to another property, all without any code. There’s no need for onEnterFrames or intervals to update the value of something. Integrating XML and other outside data sources is ridiculously easy in WPF. You can build an RSS reader in a couple of minutes. Again this is similar to the Flex environment in a lot of ways. But I would love to see Flash get this type of stuff in the future. No more having to publish the SWF to see my data! So to sum up this area, WPF clobbers Flash but is about even with Flex.

Team Workflows
One of things that Microsoft has been bragging about is how the UI, visual design, and developers on a project can all work on the same file and pass it back and forth. This sounds nice in theory, but I have to question if it’s such a good idea or not. If you have a team of wizards who are good at both design and coding, then I think it would be great. But it’s been my experience that it is hard to teach designers how to code, and equally as hard to teach geeks to design. So I think this one really depends on the situation. It could be an amazing experience or a logistical nightmare. Code is very fragile in the wrong hands and this has firedrill written all over it.

Developer Tools
So it’s not really fair to judge this are yet since WPF and the Expression IDE are still in beta. But I will say that Flash 8 made HUGE improvements to the IDE, fixing lots of little annoyances that we’ve been living with for years. The Expression IDE is pretty bad in my opinion. Microsoft makes a big deal that the IDE was actually built in WPF, the whole “we built the tool with the tool” thing. In my opinion, this is exactly what is wrong with it. Personally I’d never want the Flash IDE to be made in Flash. I want the crisp fonts and the consistent interface that I am used to when using Windows. Leave the anti-aliased text for Mac users. Microsoft needs to do some MAJOR work to this tool and I’m sure they are doing so as we speak. You know it’s bad when the Flash IDE is far superior to it! As for coding I would recommend doing it all in Visual Studio C#, which is available for free. This is an awesome code editor that has many advanced features.

Cross-Platform Support
This is the biggie! Can Microsoft make WPF a cross-platform reality? If they do then Adobe could be in for a war. If they don’t, then WPF will be left for application development and won’t ever take off on the web. Microsoft already has a Firefox plugin that they have shown at demos so this is definitely their goal. Also since XAML is XML-based, there should be a slew of tools that come out for Mac users. But this is all still speculation at this point. This is the single biggest factor that will determine the future of the interactive web. Expect some major wars in the future!

Communities and Support
I know of no other community that is as open and cool as the Flash community. It just has something that no other community has and I can’t even put my finger on what it is. We openly exchange code and help each other out without asking for anything in return. Above all that, I think that the Flash community is home to the brightest group of people I have ever seen. The originality and style that I see everyday when I look atMXNA or FWA is something that never ceases to amaze me. Microsoft has a long way to go if they want to foster this kind of community. But I have to say that I am really impressed with the WPF team and the way they are dealing with developers. Basically there are cool people at both companies whose only goal is to make really great software for us. I for one never subscribed to the “Microsoft is evil” way of thinking. When I worked at Stanford I was working on international health stuff and was amazed at how much the Gates Foundation is doing throughout the world. They are literally saving millions of lives and are changing the world through their efforts. And this is way beyond what they have to do for PR purposes. So I just look at the technologies with blinders on, as best I can that is. What can I say, I love Adobe :-)

These are just my thoughts after 3 weeks on WPF. I love working with it and it has been great to learn a new programming language. It’s still way too early to know how, if, or when it will compete with Flash down the road. But if you are an interactive designer, you will very likely have to use it someday soon. Give it a try!

My CD on eMule


Wow I guess finally arrived because my Flash video disc is being traded on file sharing networks like eMule. Of course I’d rather that they pay for it. But it’s nice to see that people actually want to watch it.

theWPFblog.com is now launched!


I’ve just launched a new blog that focuses on WPF development and will focus mainly on how it compares to Flash. I will need to start learning WPF and the Expression tool for work so I figure I might as well document my travels. From what I’ve seen and used so far, I’d have to say that I’m pretty impressed with it. Having true 3D support is something that Flash will have to face if they want to keep ahead of the competition. So come on over to http://www.theWPFblog.com and check it out!

Goodbye Stanford, Hello Frog!


Yesterday was my last official day working for Stanford. After two great years, it’s time to move on to something different. In actual fact, the funding for my job ran out. If it weren’t for that, I would have probably stayed at Stanford forever. It truly was the best job I’ve ever had. But I’m really excited because on Monday I start my new job as a Senior Design Technologist at the legendary frog design. I can’t wait to work on some different projects and I’m sure that I will love it.

Flash Forward Day 2 Recap


Finally got some good sleep. I think I slept right through my wakeup call so I had to take a later shuttle to the convention center. After getting some Starbucks I headed up to see Chris Orwig’s presentation on portfolios. He is such an amazing teacher and really knows how to captivate the audience. I’ve met Chris before down in Ojai when we were both recording Lynda.com titles. I thought it was a great session.
Next up was a session on sound design that was pretty good but I was hoping for more actual techniques oh how to create sounds, rather than when you should use them.
My favorite session at every Flash Forward is the Big Spaceship session with Garrett Nantz. He showed off some really cool stuff from the upcoming DaVinci Code movie website. The session basically focused on how they do most of their cool stuff in After Effects and then export to Flash video. But I just love his presentations and he seems like a really nice guy.
During the the first session of the day I met up with Dru Kepple, who has used gotoAndLearn() before, works in Hood River, Oregon at a company named Summit. Small world as that’s the name of the group I work in at Stanford. I went out for lunch with Dru and a bunch of his coworkers and reminisced about some old snowboarding videos. Nice meeting you Dru!
After that I ventured into the expo hall and met with the folks from Techsmith, the company that makes Camtasia. I showed them my site and they were thilled with it and are going to use it as a case example. They also interviewed me for a screencast which should be online tomorrow. I post the link when I get it. They also asked me to be on their advisory board which of course I accepted since I use Camtasia nearly everyday. I’m looking forward to working with them in the future!
Then I checked out the JSAPI session which was very informative and showed some cool ways to speed up productivity. But I doubt I will ever mess with it. Too many other things to learn :-)
I had a meeting with Michael Ninness, who’s the executive director at Lynda.com, and came up with some cool projects for the future. You’ll have to wait to see though as I obviously can’t blog about them. But Michael is probably the most down-to-earth person I’ve ever met and I’m sure I’ll be working with him in some form for quite a long time.
Next up was the film festival. It was really well done but I was a little too tired to enjoy it that much. I think most of the winners deserved to win which is always nice to see. Lynda pulled off an amazing conference this year and really raised the bar. Thanks Lynda!
I’m now in the internet lounge blogging this while everyone is at the after party. One thing I learned about myself years ago, is that I’m not a party person. To some that might sound anti-social but it’s really just a personality type of thing. If I know you well, I’ll act like a maniac. But forced socialization is something I refuse to do. Plus I don’t drink. I prefer prescription medication. Why pay all kinds of money and load on all those calories when I can just pop a xanax?
But seriously, congratulations to all the winners and I hope everyone is having a blast at the party. Hey, to me, doing this is a blast. Different strokes for different folks.
Gotta go catch the shuttle bus so see you tommorow!

Flash Forward Day 3 Recap


Got a good night’s sleep finally and managed to get some breakfast at the hotel. Plain bagel, yogurt, and OJ. Dieting sucks but I have to get my weight down if I want to last longer than 5 minutes in BJJ. Took the shuttle bus to the convention center and the driver mentioned that he wanted to get into design and was learning Photoshop. After talking with Michael Ninness, he agreed to give him a free 3 month subscription to Lynda.com. They really are the coolest company I’ve ever worked with. I can relate to the driver’s situation because I was a security guard learning HTML when I landed my first gig.
The first session I went to was with Hillman Curtis, who is has been called the master of web video. Well I’m sorry to say that I found his session really boring and wasn’t that impressed with his work. Typical New York artsy fartsy stuff. Just not my thing.
Next up I checked out the Techsmith presentation which was good but I basically know Camtasia inside and out already so I basically just checked email. Then they gave us free lunch in the expo hall and most importantly, coffee. I basically just found an empty room and chilled out for a while.
Up next I wandered into the Deconstructing Nitendogs site session. They have a very nice site, but to be honest, by that point I was daydreaming and getting sleepy. You wouldn’t think so, but going to a conference is VERY tiring. Just trying to absorb so much material in so little time is tough.
I sat through Beau Amber’s GIS mapping thingy but it was some pretty technical shit. All I took away from the session was that I don’t want to work with maps. His work was really impressive though.
Last but not least, I sat through Steve Kilisky’s After Effects session. It showed some cool AE features but didn’t really go into how it can be integrated with Flash.
Then there was the raffle and giveaway. No I didn’t win anything. That’s fine for me because I have most books and software anyway. If the tone of this posting sounds down it’s becasue I’m literally falling asleep as I write this. But just wanted to get it out tonight.
Got to talk to Lynda for a few minutes after the conference about future projects and there’s some really exciting stuff coming up.
All in all, Lynda.com did an amazing job at revamping the conference. It felt like a totally different conference. The venue was great, the sessions were good, And I met a lot of nice people.
It’s bed time. But I’m friggin’ starving. I barely ate all day. Should I just got to bed or make some food? Why am I asking you this?
Night,

Flash 8 Filters Breeze Presentation


On March 9th I’ll be giving my first live Breeze presentation on the topic Flash 8 filters. This will be my first experience with using Breeze and I’m curious how it’ll be. Most of the Breeze presentations I’ve seen have been somewhat buggy with lots of technical glitches. I’ll be giving the presentation to the Macromedia, woops I mean Adobe user group at flashusersgroup.org. Anybody can see it so go to their site and RSVP if you’re interested. It starts at 5:00PM Pacific Time / 8:00 PM Eastern Time.

Corrections to PHP/Flash Tutorial


Many people who have watched the Sending Mail with PHP tutorial at gotoAndLearn() have emailed me saying that the resulting email content is empty. This was my mistake. The version of PHP that my server is running allows you to just reference your posted information directly. So I just used $email to retrieve that value.
The correct way to do it is to use the $_POST[] syntax to get those values. So for the email you would say$_POST['email'].
If you do that for all of the sent data it should then work.
Sorry about that