71 entries in Development

Instructions on how to set up the Flash IDE for hassle-free AS3 development

Wednesday, October 6th, 2010

Flash has a few places where you can set preferences, some of which are saved globally, some of which are saved per file. The per-file settings are a pain as they are forgotten for new files.

This post describes how to:

Disable file-specific global warnings, such as migration warnings for onMouseDown

Use File > New File > Templates to specify default settings, such as turning off Always declare stage instance

Disabling warnings

I tried the adobe-recommended handler names for about 6 months before reverting back to onMouseDown etc which is far more readable in both the code and project outline in FlashDevelop. The thing is, Adobe by default in ActionScript 3.0 you get a migration warning on every publish. Annoying!

I've finally found out that you can toggle these warnings using the EnabledWarnings.xml file, by simply setting the enabled attribute to false for the desired warning.

Monday, July 19th, 2010

I've been interested in the internal structure of jQuery for as long as I can remember, but it can be overwhelming at the best of times, so I've recently made-good on my plan to build an interactive breakdown of the physical code.

Essentially, it provides a rather handy birds-eye view of the jQuery library, making it easy to dig into and understand the coding behind the seemingly-simple syntax.

Points of note:

It breaks the physical JavaScript into visual blocks that you can easiliy navigate.

I think it's fairly bullet-proof, but please get in there and test the latest version, let me know what you like, and if you find any bugs.

Check it out online and have a play – I've tried to make it super easy, and there's sample code you can use to get you started. Also, try copying and pasting some of the code Kohana classes in to see what happens!

Enable easy navigation of code using GIANT comments made up of block characters

Friday, November 14th, 2008

When navigating through large classes, it can be a real pain to find certain bits of code if you don't have a good IDE. As I often work in Flash IDE and DreamWeaver IDE, I have to rely on comment blocks here and there, with lots of – - – - – - – - – - delimiters, etc. which is an OK start.

However, I saw the PaperVision 3D classes had moved on a step from this, and had rather nice blocks at the top of each script with their logo, made out of characters. Why not extend this idea and actually build a small Flash application to let me build dirty-great big words that I can use in my scripts for navigation purposes?

Comment Headings

Edit the text in the left-hand text box to update the text in the right, then click Copy Text to copy the headings directly to the clipboard so you can paste to your IDE.

Note:Comment Headings works only with mono-spaced fonts! Mac users – you might have to experiment to find the best one.

Firefox 3 users: due to FF3's mono-spaced font tracking, the characters below may not display correctly, but rest-assured that in the final downloadable utility, and your IDE, the headings will appear just fine.

Demonstration

To demonstrate the differences between a comment-headered file and a normal file, compare the following two files, and see how much easier it is to skim through the one with larger comment headings.

Presets can be quickly called up by selecting them from the dropdown lists, which automatically updates related dropdowns as well as the output text.

Both Input Templates and Output Settings are stored in an editable text file, presets.xml, which is well-commented, allowing you to add or delete settings to suit your workflow.

To have the utility start with your chosen presets, for example having the MaxScript headings always open, just ensure its entry is first in the input list.

Customization

Once tinkering in the presets file, the following elements are configurable:

Comments – Choose the leading comments (//, –, etc) according to programming language

Blocks – Choose which characters you want to physically build the words from

Delimiters – Choose which characters you want to use to delineate each comment block

Fonts – Choose from any of 12 fonts to be available

3dsmax users

In order to display the full-block style of comments, you will need to set up the SCiTE editor to use the extended Unicode character set, and display code by default in a fixed width font. To do so, you will need to add the following lines to your User Preferences file:

Thursday, September 11th, 2008

A brief overview of the problem

A framework such as Kohana is really useful when serving lots of dynamic pages, as it allows you organise both your thoughts and your code into folders, creating order from what could potentially be chaos, at the expense of having to adhere to a structured way of working, in this case setting up controllers and methods that are correctly mapped from URLs (routes).

Whilst this is necessary for dynamic pages that need access to models, helpers and such like, for static pages that literally just need to be output to the browser, it's quite a lot of overhead, and your controllers can very quickly end up bloated with itty-bitty "view this page" methods.

What would be great would be some magic method to automatically handle static pages, without having to set up an actual controller and method, that way all you really need to create is the view file, and you leave your controllers folder nice and lean.

Note: this tutorial is for Kohana 2.2. I haven't investigated how it will work with 2.3 and the routing yet. Please comment if you have something to add!

The Fallback controller

The solution is using a default or "fallback" controller that takes care of serving views from routes that don't map to an existing controller and method.

Essentially, this new controller kicks in just after the routing has drawn a blank, locates the appropriate view file, then serves it – instead of serving a 404 page.

Step-by-step

Let's a take a look at how this works in a step-by-step approach from Kohana's perspective. Don't worry – it's actually pretty simple, I've just mapped it out specifically so you can see what's happening every step of the way.

Let's start with a route

The user navigates to a route, lets say /about/company/history

Kohana looks for

an about controller, with

a company method, and intends to supply it with

a history argument

Here's the thing though, because we did't want the hassle of setting up ALL our controllers with methods just to load views, our about controller doesn't have a company method! So what is Kohana to do?

Let's load the Fallback Controller!
Well, normally, a 404 page would be served, but using the magic of hooks, we're going to give Kohana one last chance to do something before serving that horrid 404 page.

application/controllers/fallback_page.php – Set up a controller to do the business

class Fallback_Page_Controller extends Page_Controller // page controller is my standard page template
{
public function __construct()
{
// the constructor can be omitted if you're not doing anything special,
// as the parent constructor it is called automatically
parent::__construct();
}
public function __call($function, $arguments)
{
// search for a view, and load it if it exists
// it's up to you how you handle the mapping of arguments to folders here!
$route = implode('/', $arguments);
if(Kohana::find_file('views/main', $route))
{
$this->template->content = new View('main/'.$route);
}
// display alternative content if not found
else
{
$view = new View('common/404');
$view->info = array($function, $arguments);
$this->template->content = $view;
}
}
}

Conculsion

So now you should be able to set up a bunch of views, but needn't worry about building controllers for them if nothing exciting is happening.

The fallback controller will run, will attempt to find a matching view, and if found, will echo it the page. The main thing is – it keeps your controllers folder and classes nice and lean, and you only need to build controllers that actually DO any controlling!

A robust helper to handle everything file and folder-related within Kohana

Wednesday, August 20th, 2008

Kohana is just an excellent framework to work with, but one of my beefs is that the structure of its bundled libraries and helpers is a little haphazard, missing basic functions you'd expect to find in the core (so you can rely on them when writing modules) omitted!

For this reason, here's my attempt at a more integrated helper class. It's somewhat of a Frankenstein's monster with bits borrowed from Code Igniter, and my own code thrown in as well. Apart from this, it:

Friday, June 6th, 2008

As 3dsmax doesn't allow for either associative arrays or dynamically-set object properties, it can be difficult to store unstructured, arbitrary variables.

Sometimes you just want to store lists of name/value pairs, to keep track of a few settings throughout your script, without relying on a host of variables, resorting to .ini files, or custom attributes.

Therefore, I set about writing a basic Dictionary, or List struct, similar to VB and other languages.

Example code

Here's a really basic example of storing 5 named variables within a List:

Download

Monday, May 26th, 2008

Overview

In response to a post on CG Talk, Optimization ideas needed, a few other developers and I us pitched in to help out with ideas to solve a puzzling problem.

The issue was that a loop to attach 7500 objects was taking up to 8 minutes to complete. Where did the problem lie? Was it in the transformation code, the attachment code, or somewhere else?

Well as luck would have it, today's Bank Holiday has been totally washed out with rain, so I had nothing better to than to do some testing and find the cause, and in the process road test my recently-developed TimeStamper struct.

Approach

After turning undo and redraw off, as well as optimizing the transformation code within the script, which cut a 1000-object test scene's processing time in half, surprisingly the 7500-object scene was still taking around 8 minutes.

I suspected that the problem may well be in the fact that as mesh gets larger, perhaps it becomes computationally more expensive to add new meshes, seeing as the entire array of points and faces needs to be evaluated every time a new mesh is added. Cumulatively, this could really add up.

I though that perhaps the right approach would be to split the attaching up into phases, using a 2D loop, and I suspected that perhaps the square-root of the total attaches might yield the optimal performance, ie for 10000 attaches I'd perform a 100 x 100 loop, creating 100 intermediate meshes, then attaching them all at the end.

Results

These are the results for various variations of 2D loops, limiting the amount of objects attached per loop. The results are impressive!

For 1000 objects, the optimum loop combination was 31 loops of 32, a speed increase of 12 times over a single loop

For 3000 objects, the optimum loop combination was 55 loops of 54, a speed increase of 22 times over a single loop

For 5000 objects, the optimum loop combination was 50 loops of 100, a speed increase of 28 times over a single loop

For 7500 objects, the optimum loop combination was 87 loops of 86, a speed increase of 30 times over a single loop

And yes, the square root approach was most successful 3 out of 4 times.

Here are the results in table format, with the optimum loop highlighted:

1D / 2D loop comparison

Compared to the 1D loop, the 2D loop was 30 times faster on 7500 attachments.

In minutes and seconds, that means a decrease from 6 minutes and 29 seconds to just 12 seconds!

In graph-form that looks like this:

Conclusion

It seems pretty safe to say that in this case, building up intermediate meshes and attaching at the end is the best way to go. It looks likely that adding to already-huge arrays carries with it an overhead that can have an extremely negative effect in a lengthy loop situation.

I've no doubt that this approach most likely extends to other mesh / array / hash based computations as well, so splitting up large cumulatively-expensive calculations into smaller chunks could well be a great time-saver in other tasks as well.