• 1:46 pm, 22nd April 2008
  • xbox 360
  • 4 Comments

GTA IV / Xbox 360 TV Spot

The GTA IV hype machine continues to gear up for its release and Microsoft clearly want to make the most of what could be a USD400 million launch week. When the hype is this well produced keep it coming I say… but roll on Tuesday :)

  • 10:10 am, 19th April 2008
  • bbc
  • No Comments

Links and things

Links and things

  • AS3 coding conventions
    Worth a read. Some stuff in there I haven’t been doing :/ [via BIT-101]
  • BBC Sound Index
    Marketed under the BBC Switch banner, Sound Index attempts to build charts of the most popular artists using social networking sites. The idea has been kicking around for a while and under the primary-coloured exterior there lies a lot of data which will hopefully be opened up. Its in beta at the moment so will be interesting to see how it develops.

Run-time class and asset sharing across multiple SWFs in Flex (AS3)

I have recently ported some Flash 8 widgets to AS3 for use in a prototype site we will be launching in the next few weeks. The widgets are all quite simple, displaying graphs, but became fairly heavy due to an embedded font and graphics. All told the four SWFs totalled over 300K so I decided to do some optimisation.

Sharing library assets and classes at run-time means the user can download (and cache) the library SWFs once and use them across the visible SWFs in the page. Doing so has reduced the total footprint to under 100K and has the added bonus of meaning I can change the font for example without having to re-compiled the visible SWFs.

Sharing simple assets

For some of the widgets, access to remote assets was required from more than one class. To achieve this, I wrapped the asset and embedded font classes in classes with static access:

Shared assetsThe static asset access class looks something like this:

package com.fridayforward.sharedAssets {
    
    public class Library {

        private static _callback:Function;
        private static _assets:LoaderInfo;

        public static function init(callback:Function, url:String="../sharedassets.swf"):void {

            // set callback function
            _callback = callback;

            // load assets            
            var request:URLRequest = new URLRequest(url);
            var loader = new Loader();            
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
            loader.load(request);
        }

        private static function onLoaded(event:Event):void {

            // retrieve assets
            _assets = LoaderInfo(event.target);

            // callback
            _callback();
        }

        public static function getAsset(id:String):Sprite {

            // return asset class
            var c:Class = _assets.applicationDomain.getDefinition(id) as Class;
            return Sprite(new c());
        }
    }
}

The assets are loaded in the application constructor, with a callback to continue once assets are available:

package {

    import com.fridayforward.sharedAssets.Library;

    public class Application    {

        public function Application():void {

            // load assets
            Library.init(init);
        }

        private function init():void {

            // now have access to asset library
            // continue with application...
        }
    }
}

The assets can then be accessed from anywhere within the application:

var myAsset:Sprite = Library.getAsset("MyAsset");
addChild(myAsset);

This worked nicely for sharing simple assets but I also wanted to share embedded fonts used in TextFields. To do this, I created a separate AS3 application which contains a class that embeds any fonts I want to share and creates TextFields using them. This class is then made available through a static class to all parts of my applications.

The static Text class looks something like:

package com.fridayforward.sharedFonts {

    public class Text {

        private static _callback:Function;
        private static _textField:Object;

        public static function init(callback:Function, url:String="../embeddedFonts.swf"):void {

            // set callback function
            _callback = callback;

            // load assets
            var request:URLRequest = new URLRequest(url);
            var loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
            loader.load(request);
        }

        private static function onLoaded(event:Event):void {

            // retrieve assets
            var tfClass = event.target.applicationDomain.getDefinition("EmbeddedTextField") as Class;
            _textField = new tfClass();

            // callback
            _callback();
        }

        public static function textField(text:String, size:uint, color:uint=0, ...):TextField {

            // pass to EmbeddedTextField object
            return TextField(_textField.textField(text, size, color, ...));
        }
    }
}

The root class of the EmbeddedText application simply acts as a wrapper to allow access to the contained EmbeddedTextField class:

package {

    import com.fridayforward.sharedFonts.EmbeddedText;

    public class EmbeddedText extends Sprite {

        public var embeddedTextField;

        public function EmbeddedText():void { }
    }
}

The EmbeddedTextField class provides the functionality to create TextFields:

package com.fridayforward.sharedFonts {

    import flash.text.AntiAliasType;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import flash.text.TextFormatAlign;

    public class EmbeddedTextField {

        [Embed(source="...VAG Rounded BT.ttf", fontName="VAG", mimeType="application/x-font")]
        private var vagFont:Class;

        public function EmbeddedTextField():void { }

        public function textField(text:String, size:uint, color:uint=0, ...):TextField {

            var format:TextFormat = new TextFormat();
            format.font = "VAG";
            format.size = size;
            format.color = color;

            var tf:TextField = new TextField();
            tf.text = text;

            return tf;
        }
    }
}

This is then accessed in the same way as before:

package {

    import com.fridayforward.sharedFonts.Text;

    public class Application {

        public function Application():void {

            // load assets
            Text.init(init);
        }

        private function init():void {

            // continue with application...
            addChild(Text.textField("Application Title", 20, 0));
        }
    }
}

If you have a large library of assets you need to load it might be a good idea to display a preloader while waiting for them to download.

  • 8:26 am, 10th April 2008
  • misc, web
  • No Comments

Links and things

  • Super Mario in 14kB Javascript
    That pretty much sums it up: someone has recreated (some of) Super Mario Bros in a very small amount of JavaScript. Amazing.
  • 1:37 pm, 6th April 2008
  • bbc, events
  • No Comments

BBC Innovation Labs

Every time I start to contemplate leaving the BBC (its 5 and a half years and counting) I get the opportunity to participate in something which I I probably wouldn’t get the chance to elsewhere. In the past it has been an inspiring conference and last week it was representing BBC Audio & Music Interactive as commissioner at the Innovation Labs in the North West of England.

Lake Windermere sunset

Having shortlisted 10 proposals pitched across Future Media & Technology and Vision disciplines, the teams of ‘professional creative technologists’ (as the Labs’ about page describe them) spent a week developing their idea and their presentation techniques. Half-way through the week we, the commissioners, joined them and helped them to focus their pitch before presenting them on Friday morning.

While only a few of the proposals were commissioned on Friday, both the independent companies and the BBC gain a great deal from the process. It was a great opportunity to meet people from across BBC Future Media & Technology and Vision (it is a big place after all) and discuss problems and ideas with creative people from the commercial sector. The teams themselves gained as much from each other as they did from the organisers and leave (at the very least) with a small pile of business cards in their back pockets.

Last.fm

  • No recently listened tracks.

Twitter