Archive for the 'Flex' Category

removeEventListener causing memory leak?

Update

After inspecting my dispatcher .. i find this awful mistake:

override public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0.0, useWeakReference:Boolean=false):void {
_node.addEventListener(type, listener, useCapture, priority, useWeakReference)
}

override public function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void {
_node.addEventListener(type, listener, useCapture)
}

(DOH!!!!!!!!!! LOL)

——

To cut to the chase, in my personal AS3 framework, I’ve implemented deconstructors in all my DisplayObjects objects. The deconstructors mostly feature removeEventListener calls as I try to stay away from using weak refs. Today, while making a regular memory leak check using Flex Builder 3’s profiler, I noticed that I had a few DisplayObjects still latched onto an event dispatcher model object they were supposed to have let go of.

The first thing I did was to put a trace() in my deconstructor to make sure it was being called, yes it was. WTF? After some more digging, I then saw that this particular DisplayObject was flagged to not attach itself to the event dispatcher in the first place. (Wait, you mean that addEventListener hadn’t even been called in the first place? Yes!) So I switched the flag so that the DisplayObject would attach to the event dispatching model and guess what, this time it got GC’d after the deconstructor call.

So why is removeEventListener causing this to happen, the API docs define the method as:

“Removes a listener from the EventDispatcher object. If there is no matching listener registered with the EventDispatcher object, a call to this method has no effect.”

Has no effect, huh? But it seems to be doing something. Has anyone noticed anything similar to this?

Click to Read: Microsoft Caves In, Pays EOLAS

This is a good news day for online Flash Platform developers. Microsoft has finally managed to open its FAT wallet and pay EOLAS for the ability to “… automatically invoke external applications providing interaction and display of embedded objects within a hypermedia document” .. basically get rid of the whole ‘Click To Activate’ thing.

Though to be fair to M$, this patent is the biggest mound of crap ever! They shouldn’t of had to deal with it in the first place if the patent system was fair. But even though it’s a B.S. patent, MS shouldn’t have passed the mess onto everybody else. The whole ‘Click to Activate’ problem just goes to show that Microsoft cares more about money than it does about UX. In-fact, this is probably just one if a million examples .. haha.

So what does this mean now? Do we all abandon our JavaScript embed workarounds and revert back to hard coding the embed code back into HTML? Well, I think that maybe the whole EOLAS mess might of been a wake up call to way we do embed our Flash. Having a JavaScript wrapper only improves the flexibility of our embedding and also makes all those W3C syntax checker nuts happy. But on the other hand, the hard embed worked in the past, so there is no reason why it wont work just as well in the future. Is there?

Well, if your looking for direction on this matter, my advice is to keep your JavaScript workarounds. You never know when/if EOLAS will go knocking the doors of other browser vendors. And as far as I know, the Opera browser will still have the ‘Click to Activate’ implementation.

This news form Microsoft is too little too late, the damage has been done. JavaScript workaround are now the norm and are here to stay .. thanks EOLAS .. *pause* .. NOT!

For the official dates and details from Microsoft .. Click Here

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 :)

Briefly: RIA Camp at Adobe SF

I’m planning on attending RIA Camp next week at Adobe. So, if anyone wants to talk San Francisco Flash Platform User Group with me, then you should come on down. These small camps are always fun :)

Flash IDEs Need a Rebranding

The Flash world never sits still. Its drum beats relentlessly and recently the tempo has been significantly upped. Developers are slowly waking up to new tech terms such as Flex Builder, Flex Framework, AIR and “Thermo”. And trust me, a good number of “developers” find it hard to keep up. I can’t even express how sick I am of people referring to AS3 as Flex.

It used to be that the only thing Flash developers used to have to worry about was the version of the Flash player and its related Flash IDE. Now they have to deal with a whole platform family. Below is a brief list of the Flash IDE version timeline:

  • FutureSplash Animator / Flash 1 (1996)
  • Macromedia Flash 2 (1997)
  • Macromedia Flash 3 (1998)
  • Macromedia Flash 4 (1999)
  • Macromedia Flash 5 (2000)
  • Macromedia Flash MX (2002)
  • Macromedia Flash MX 2004 (2004)
  • Macromedia Flash 8 (2005)
  • Adobe Flash CS3 (2007)

Apart form the whole MX period and the Adobe CS merge, the IDE version timeline appears to be quite simple and straight forward. But wait, I forgot to add Flex Builder right? or did I? Does it even live in this list at all? And what happens when “Thermo” is released?

The most prominent part of the Flash IDE has always been its timeline and rightly so, it’s an animation tool so I hear. But hold on, how many other animation tools do you use to create non-animations with? The problem is that Flash is now this ultimate multimedia platform, it ticks all six boxes extremely well - image, text, video, audio, animation and interaction. So, we need new IDE’s to deal with all of this richness and of course Flex Builder is the start of this and “Thermo” is following. But why is it all based so heavily around the Flex Framework?! I don’t get it (*confused look*). I mean, why is it even called Flex Builder? I use Flex Builder daily, but never touch the Flex Framework or code in MXML. (side rant: why can I only use MXML with Flex Framework anyway!).

I propose that the Flash Platform be repackaged into clearly named products:

  • Flash Animator (currently know as Flash)
  • Flash Builder (currently know as Flex Builder)
  • Flash Designer (currently know as “Thermo”)

From this new starting block, the IDEs could then be sold individually or in bundles aimed towards specific markets (I waiting for Microsoft recruiting to give me a call any second now…)

  • Flash Platform - Animator, Builder, Designer, Flex Extended (charting)
  • Flash RIA - Builder, Designer, Flex Extended (charting)
  • Flash Creative - Animator, Designer, Photoshop

Of course, the whole renaming idea could possibly only cause more problems. I know I hate it when stores always move their goods around for no reason and it’s the same with product names. But I think that the current naming scheme for the Flash Platform is really messy and it only seems to add confusion. Someone who has used Flash IDE all their lives is less likely to look at Flex Builder as it seems to be called something other than Flash. The player and the IDE in the past have always shared the Flash mark and it should continue stay this way for the platform to be approachable and accessible.

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 :).

“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!