Archive for the 'ActionScript' Category

Crazy AS3 Runtime Error

In all the months I’ve been authoring ActionScript 3, I’ve never seen a runtime error as cool as this:http://thebackbutton.com/misc/best_stack_dump_ever.txt(note: some package/class names have been masked)I managed to get this error when I called a temperately disabled function, renderPlotsHandler(e:Event):void. And when I say disabled, I simply mean that I added a ‘return;’ to the first line of the function.So, I have no idea how I managed to get this error if the function did nothing?!Crazy :)

Flex-less MXML: The Flash Evolution

The greatest thing about the Flex Framework in my eyes is its utilization of an XML based language (MXML) for it’s primary scripting. MXML allows you to create, bind and structure objets in a very straightforward manner. This then leads into other advantages such as rapid prototyping and development and so on and so forth.

Mark-up languages have always been easy to author and understand, just look back at HTML for example. Your average person interested in tech could pick up basic HTML in a very short space of time, then boom, their a web developer just by understanding the behavior of a few predefined tags. A mark-up developer never really wonders why the page is working the way it is, they never wonder why they get constraint and layout flows for free and its OK if their code isn’t perfect as they still get some kind of output from it (unless they went wild with a comment tag).

And so now with MXML, it’s proven that an XML based language can work in the context of creating ActionScript applications. So why is MXML limited to the Flex Framework? Well, the simple answer is that a lot of the META-tags and curly-braces used in the MXML language are only compatible with the Flex Framework. Those little snippets are the worker bees of the Flex Framework who fly around making sure everything is hooked up correctly into the underlaying ActionScript.

So does this mean that Flex-less MXML is nonstarter? Well almost, as I mentioned before, MXML’s rules, constructs, methodologies are all linked to the Flex Framework. But what if we could create our own rules, create our own “worker bees”, then we would have Flex-less MXML right?

This of course throws up a thousand different questions like: Would this even be know as MXML anymore? Would it give birth to languages such as FVX (XML for Flash Video) and GEXML (XML for Flash Gaming Engine) or FFBX (XML for Flash Facebook Applications)? How would you define all the rules need to create these languages? Cant we just build our own compilers for this?

Would the creation of all these variants be a good thing? Who knows, who cares!, the point is that then people would have a choice of how they want to develop in Flash, this is so important! As ActionScript becomes ever more verbose and powerful, its adoption rate with newbies will fall because its just too much for the casual developer to pick up.

This brings me back to the point about only having to learn just a few predefined tags. The Flex Framework shall only get bigger and so shall its documentation. Its wizards shall grow in number to counteract this growth, but in the end, the framework shall become almost as hairy as AS3 to the casual developer. We need mini XML frameworks built for targeted needs for the Flash Platform to flourish and evolve.

I know this shall happen in the next few years, but the question is when? Shall it be Adobe who takes the necessary steps or shall it be the community? I look forward to the years ahead :)

Generate Filter ActionScript 3 From DisplayObject’s

Filters in Flash are great, but I do have one big problem when working with them. As I’ve stated many times in my blog, I’m quite the ActionScript purist and I hardly touch the Flash IDE or FLA files. Thus visualizing a filter purely in code can be quite a pain. So sometimes, I’ll open up the Flash IDE and work on creating the filter settings with the help of the nice GUI controls. The problem is then converting all of my filter settings back into reusable ActionScript code.

To make this process a little easier, I took two minutes out to create an ActionScript class that accepts a display object as an argument, and then traces the ActionScript code needed in order to recreate the filter to the output console.

Check it out …

Zip File | Source

See the example below

Read more »

Recruiting: San Francisco Flash Platform User Group

Disclaimer: If there is already a San Francisco Flash Platform user group in existence, please let me know and ignore this post.

From my observations, I’ve heard of many Flash user groups from all around the world. The first few that spring to mind are based in Boston, LA, London and Belgium. They all seem to attract a good following and these people seem to want to share what they know and love with other like minded individuals.

So, what’s the motivation behind this post. Well, for the past few years, I’ve been a bit of a Flash lone wolf, as I’ve always ended up working as the only ActionScripter in my workplaces. Even now at Sony, I’m working in an office full of C engineers and one IA person. I have no one to talk ActionScript with!

At lunch times, I’ll sometimes take the short walk down Townsend St to get a burger from the Holy Grill, passing the SF Adobe building on the way. And I feel that I can’t be alone in my ActionScript world with the Flash mother-ship right next to me. haha.

For these reasons, I feel compelled to start a San Francisco based Flash Platform user group (see Disclaimer). To start recruiting people, I’ve setup a group hosted on Facebook (yes, I know it’s not the best solution and it’s only temporary) so, if your based in the Bay Area, with a love for anything Flash / Flex / AIR / ActionScript / MXML related, I would encourage you to join in!

When and if the group gets a big enough following, I’ll make another posting, both on here and on Facebook, outlining plans for a first meet to discuss how the group shall be organized.

I feel that any kind of group should be as democratic as possible, so please, if you have any suggestions or feedback on what I can do to make this group a success, please don’t hesitate in leaving me a comment or email.

Let’s make it happen! :)

Speed up Flash with Stage Quality

Ever since the release of Flash 8, I’ve rarely published a Flash project with a HIGH stage quality. If you know why, then you can skim this post and leave me a high-five in the comments, if not then read on …

So what’s stage quality I hear some of you asking? Well, you may of seen it feature within the default context menu of the Flash Player. And this small setting defines how certain elements are anti-aliased/smoothed within your Flash application.

Here are the four available quality settings:

  • StageQuality.LOW - Graphics are not anti-aliased, and bitmaps are not smoothed.
  • StageQuality.MEDIUM - Graphics are anti-aliased using a 2 x 2 pixel grid, but bitmaps are not smoothed.
  • StageQuality.HIGH - Graphics are anti-aliased using a 4 x 4 pixel grid, and bitmaps are smoothed if the movie is static.
  • StageQuality.BEST - Graphics are anti-aliased using a 4 x 4 pixel grid and bitmaps are always smoothed.

So, HIGH and BEST sounds really awesome right? Think again! Let’s take a brief look at (vector) graphics:

Vector graphics (also called geometric modeling or object-oriented graphics) is the use of geometrical primitives such as points, lines, curves, and polygons, which are all based upon mathematical equations to represent images in computer graphics. It is used in contrast to the term raster graphics (also know as a Bitmap), which is the representation of images as a collection of pixels, and used as the sole graphic type for actual photographic images.

When Flash renders a vector graphic, the bitmap result of the vector data is calculated on the fly. This can be awfully taxing on the users machine depending on how complex the vector graphic drawing is. A large part of this calculation goes on smoothening-out all of the lines and edges so that you end up with something that doesn’t look jaggy, and this is where the quality setting comes into play. You can think of the quality setting as accuracy level of anti-aliasing. So, the higher the accuracy, the more work has to be done when rendering.

So what changed in Flash 8?. Well, Bitmaps staged a military coup and took the crown away from vector graphics of course (err). First off, we got the cacheAsBitmap flag, this took a lot of stress of rendering complex vectors away such as UI components. Then we got the awesome BitmapData class (its like a freaking Swiss army knife!), and finally we got Advanced embedded text rendering. The new text rendering is the most important reason for not using HIGH anymore as it does not suffer from jaggies in lower modes.

Back in 2005, I created my first Flash 8 website while working at Sparkart for Mike Shinoda’s side project, Fort Minor (http://fortminor.com/site.php). I really wanted to dip my toes into as many Flash 8 features as possible. So, in the site you’ll see blend modes, blurs, vp6, BitmapData (used for image flattening) and advanced text. But the best thing about all of this is that the site stage quality is set to LOW! Now, this site wont win any awards for usability and the code is rushed (~2.5 week project) but you’ll see how I was able to push the speed of the animation by setting the quality to LOW without really loosing anything visually. An important thing to note from this is that the site has no vector graphics, its all bitmap based.

This brings me briefly onto Papervision 3D developers who actually inspired me to write this post. Today, I came across the papervision based game “Downtown Maze Master” from Nissan. I noticed that the game was running in HIGH mode through the games context menu as my MacBooks core was running at 77% and my laptops fan soon fired up. Thanks again to the context menu, I took the setting down to LOW and immediately watched my core usage go down to 54% without any anything visually bad happening in the game. I’d usually expect papervision3d developers to be close on the bleeding edge of Flash, so I wonder why the quality setting was forgotten. And this site is only once of many papervision3d sites guilty of this sin. End of rant, spread the word :).

Bitmaps rock your sock in Flash, but what about if you need to resize bitmap elements? Well in my world today, I work mainly on creating application UIs vs website experiences, and my best friend is 9 slice bitmap scaling. To read more about 9 slice resizing, check here. But what about if you still need to utilize vector graphics and run with a LOW setting? Well, you may still need to use the HIGH setting if your vector is quite dynamic and/or shape tweened. But if your only planing to pan your vector around the stage, then you might be able to use LOW successfully if you “flatten” the vector to a Bitmap in HIGH mode, then switch back to LOW.

// ActionScript 3

stage.quality = StageQuality.HIGH;
var shape:Shape = new Shape();
shape.graphics.lineStyle(2,0xcc00cc);
shape.graphics.drawCircle(100,100,100);
var bitmapCanvas:BitmapData = new BitmapData(200,200,true,0xffffff);
bitmapCanvas.draw(shape)
stage.quality = StageQuality.LOW;
var circleImg:Bitmap = new Bitmap(bitmapCanvas);
addChild(circleImg)

The result will be a wonderfully anti-aliased circle shown in LOW mode. This method also works well for cutting down the number of elements on stage in general, just think of it as an uneditable cacheAsBitmap.

The lesson I want you to take from this post is to always play with your default quality mode before pushing your site live. You just might get a pleasant surprise :).

I Need To Contribute ActionScript 3

I want to start an open source AS3 project(s) here on The Back Button. Woo! One problem though, I don’t know what it is I want to create! :(

This is where I need you, the community, to pitch in ideas. So, what are you missing in your day to day ActionScript life’s? What do you find yourself doing over and over again? What do you hate most about ActionScript 3?

I just love creating reusable, flexible, purist code and would love to solve as many problems as I can.

So, please leave comments here or email me directly at bustin:at:gmail:com

Let’s do it! :)

p.s. I’d rather stay AS3 only right now, so please, no Flex Framework/MXML request.

“Thermo” Prediction

There is talk in the town of a new Adobe product codenamed “Thermo“. The first thing that comes to mind is a UK sit-com called “My Hero” featuring ThermoMan, but i’m nearly 99% sure it holds no connection. So what could it be?

The way I see it, Flash platform today has two main IDE’s; the first is Flash Pro and the second is Flex. Lets sum up these two IDEs:

Flash Pro - I see it as being a relic in todays world of application development. It’s far more suited to animation, which of course, is the origins of Flash remember?! It’s great for creative people to produce great looking visuals, but not so great for creating applications. Especially now you need to know AS3 which, most designers will find daunting.

Flex Bulder - Rapid application development using the Flex Framework that is not famous for it’s visual creativity. It’s the best AS3 editor/compiler IMO, that’s why I use FB2 currently to code all my projects. IMO, I think Flex is as exciting as visiting a box factory. Don’t get me wrong, boxes are extremely useful :).

It is amazingly obvious that there’s a gaping hole here; there’s no IDE for creatives to produce visually pleasing Flash applications. So what’s the solution? Well my guess is that “Thermo” will be the solution. So what will “Thermo” be? Well my prediction is that it shall be somewhere in the middle of After Effects/Apple Motion (remember that Flash 10 may be hardware accelerated), Flash Pro, Apple Automator and Flex. I think that “Thermo” shall be very drag-drop/WYSIWYG orientated (think After Effects/Apple Motion) and shall only require minimal “coding” (think Apple Automator or Scratch). Also, I think that all the workflows/effects and motions connected to these features shall be be sharable and Adobe will host them all freely.

This is my prediction for Thermo, let’s wait and see what happens next week :)

Welcome to the Back Button

I’ve done it! Ive broken into the world of Flash blogging :).

One on my goals for 2007 was to start a blog, but I never did have the time to build what I’d visioned. I wanted to build my own custom Rails CMS and then front it in glorious ActionScript, but alas I never did have the spare time and motivation happen together. So for now, I’ve defaulted to WordPress and borrowed this basic theme. I’m sure though as the weeks and months progress, this shall start to change (well, I hope).

So, what can you expect from this new blog? Well, let me start by giving a brief overview of my background. I am proficient in most areas of Flash, I have been using Flash since Flash 4 and today my strongest area of Flash is AS3 and my weakest is the Flex Framework. (Don’t get me wrong, I know the basics and methodologies of Flex, I just haven’t found a reason for using it yet.)

I used work for a company called Sparkart (based in Emeryville, CA) where I created Flash websites/widgets for the music industry for big brands such as Linkin Park, The Killers, Eminem and Tim McGraw. And now I create Flash application (prototype) UIs at Sony (San Francisco, CA) supporting C middleware development.

I can’t imagine a life without Flash :)

I’m planning to post experiments, original tips, comment on platform news & developments and anything I feel relevant. So please keep on visiting and please please leave me comments!

« Previous Page