Archive for November, 2008

Using Flex UIComponent width and height

Monday, November 24th, 2008

AS you might know, the only way to add Sprite based classes into a Flex project is by adding them to a UIComponent or a subclass of UIComponent. This adds some extra complications. One of these is that UIComponent does not report width and height correctly. If provided with an explicit width and height, the UIComponent’s size will be set to whatever it was when initialised and will not change if, for example, the contents of the component are scaled. This means that whatever contains the component will not respond appropriately. Dynamic sizing doesn’t seem to work at all. (As an aside, I do think that this is rather a poor implementation, since it breaks the existing functionality of DisplayObject)

In order to correctly set the size we need to recreate the DisplayObject functionality in order that from outside the component we can see the changes in size. In order to do that, it’s necessary to understand how UIComponent (and by extension, most of the other Flex components) is set up and handles sizing.
(more…)

Rockin with the Brighton Massiv

Friday, November 21st, 2008

You wan freelance? We got freelance. (If you’re in Brighton (or London (or anywhere, it is nearly 2009 (where did that go?) now) ) which, let’s face it, you wanna be).

Presuming I haven’t lost you with all the nested brackets, I’ve been kindly linked to by a few people now on the list of the top Brighton Flash Developers. Clearly it would be rude not to do likewise…

Here’s my list in alphabetical order:

Designers/Animators

Charis Mystakidou (wiredportfolio.com)
Kristan Akerman (sting.co.uk)
Luke Hornsby (flamingpixels.co.uk)
Tim Frost (bullandgate.com)

Developers

Me (here and also my company steamshift)
Matt Pearson (actionscripter.co.uk)
Matt Sayers (soplausable.co.uk)
Neil Manuell (revisual.co.uk)
Nikos Chagialas (devgallery.com)
Richard Willis (richtextformat.co.uk)

There were some more, but I think they’ve all been employed by plugin-media :)

swc fix

Wednesday, November 19th, 2008

Seems I was right (well, let’s see shall we…) in my hypothesis regarding swcs in the same folder as the fla. In order to test this, I started up a new Actionscript project in FlexBuilder and created an assets folder. In Flash I opened a new fla, which I saved into the folder and then began to load it up with assets. At 32.4MB and 130 odd symbols (including videos, vector symbols, images and sounds) my swc finally broke and wouldn’t import into Flex properly. I then created a swc folder in Flex Builder and set the fla to import into that folder. Importantly, I also deleted the swc + swf from the assets folder. After recompiling the fla and rebuilding my Flex project, everything magically worked again.

I hope this helps someone out!

swcked witch

Tuesday, November 18th, 2008

Since my unbridled enthusiasm for swcs a few posts ago, I’ve been sharply brought down to earth about just how unreliable they are. I’ve come across a couple of different problems that just defy all logic. While I still think they are by far the best solution for projects where you want to have your assets compiled into the swf, there are some things that will make you want to stop doing Flash development and go take up pig farming instead.

1) Sometimes your swc will just fail. This seems to be in some way related to the number of assets in the fla, but not neccessarily. You’ll know you’ve got this one when the previously fine references to the swc classes suddenly break, as though it can’t find them. Richtextformat has got a full explanation of the “solution” to this problem over on his blog.

2) Your swf can’t find the document class anymore. I have an fla that held all the assets for my Flex based project. I’m compiling this to a swc and then using that as a library. All fine. However, the designer doesn’t have Flex, so he wants to compile directly from the Flash IDE. So, I set up the document class for him. However, when the fla is compiled, nothing appears. No errors, no traces from either the document class or the timeline. Nada. The problem was that I had left Export SWC on in the publish preferences. Unticking Export SWC did nothing however, it required the swc to be deleted. Then, it worked. All I can assume is that Export SWC was generating a duff swc, which in turn was breaking the swf.

The solution workaround hack I’m using is to have 2 flas. One is set up for compilation from the Flash IDE, the other a blank, unsaved fla (as per Mr TextFormat’s instructions) to generate my swc. This is a pain in the arse, let’s be honest. Every time the fla is updated, I have to refresh the swc fla assets and recompile. I guess I could write some kind of jsfl script to do it for me, but I’ve wasted enough time on this already :(

Anyway. It seems that the Export SWC command in CS3 is really broken. I’m going to try on CS4 and see if it’s been fixed. Fingers, toes, tentacles and any other prehensile appendages crossed.

[Update - It seems like this issue only occurs if you are building the swf/swc into the same directory as the fla. I've tried it with a couple of builds to outside the directory, and it seems to be ok - there might also be an issue if the fla is inside the Flex directory structure but I haven't confirmed this. More testing is needed...]

Dynamic Framerates

Wednesday, November 5th, 2008

One thing that I’ve started using in most of my projects where the processor could get hit heavily is a dynamic rendering system. This seems to be working really well, so I thought I’d share it.

I came across the idea from this post over at 8 bit rocket. The idea is pretty simple. A timer is set to run as fast as possible. Every time the timer executes, it runs a render cycle and a code cycle. It then checks how long the total cycle took and does 1 of 2 things. Either it sleeps for a certain amount of time, so that the swf doesn’t run too fast, or the next render cycle is dropped so the player can catch up. It’s a little more involved than that so if you want to know the finer details, head on over there.

I made some crucial adjustments to the code that’s presented there however. The biggest one was to make the code into a class, so that I could use it more easily. I’ve set up a system for registering renderers and updaters so they can be added and removed from the timer, and also added some events that get dispatched on render and update cycles. It works really well if you have an MVC setup, since the model and the view are already separate.

The source code is available here. Documentation after the jump.
(more…)