Archive for the ‘structure’ Category

in bed with … [EMBED]

Monday, July 26th, 2010

Using flash develop or FDT and sick of going back to CS4/5 just to create some swc’s that you might have to change everytime you update any of the assets? So 2000 and something…

Use embeds!

I started using a generic static class to add all my embeds for a project and then you can easily draw them from there.

The static class:

public class HomePageAssets {

[Embed(source="../../../bin-debug/assets/loader/bar.png")]
public static var BrandBar : Class;

[Embed(source="../../../bin-debug/assets/loader/dude_again.png")]
public static var DudeAgain : Class;

[Embed(source="../../../bin-debug/assets/loader/logoType.png")]
public static var LogoType : Class;

...

And in any class:

addChild(new HomePageAssets[myAssetVar]);      // e.g. "BrandBar"

Njoy!

AS3 – VO thoughts on…

Friday, July 23rd, 2010

I started to use static VOs in my framework and having fun doing so.For those who dont know what a VO is, its a ValueObject.As a friend recommended I am using them solely as static classes, meaning I dont create an instance, which should keep memory leakage down and make them available globally.

So far I am using two types as I would describe them:

1) property based: where I defined property get-setters for everything I want to store (mainly strings) some even constants, so a very non-depth storage object

2) list based: where I need a storage for many of the same kind of objects and search functionality and add and delete function basically this is a searchable fancy array which is static and therefore available everywhere. Neat.

I like the simplicity of those classes. They are framework, nearly language independent or sorts. Now if anyone out there knows how secure it is to have global code flying about , please comment.

getDefinitionByName() – best thing since sliced bread

Tuesday, November 3rd, 2009

Among one of the coolest things I came across in Flash’s Actionscript 3 is the class ‘getDefinitionByName’. What it does (in short) is turning a class name in the form of a String into a class you can create an instance from. What this means is, you can create most flexible class creation built on cases.

E.g. instead of building a long switch…case list, you can add string names based on the elements an instance should have and call the specific class.

I use it for example to have a component that can call clips and bitmaps graphics from the library. The clip name can be handed over by XML and the appropriate clip can be added, without re-render or re-coding of the component.

I also build a centralized component-mediator control, that stores all possible pairs, so whenever I call for a component to be used in a mediator, it calls the right class. Which let’s me leave the display engine as is and only the content central changes from application to application.

Here is how I use it in a pureMVC environment:

var tMediatorClass:Class=getDefinitionByName(myMediatorClassName)  as  Class;
facade.registerMediator(new myMediatorClass(myComponent.id,myComponent));

There is though, one tricky issue. As long as you don’t mention a class’ name in the code, the compiler won’t implement it, meaning that your app will throw an error. Therefore, I changed my code to this:

var tMediatorClass:Class=getDefinitionByName(myMediatorClassName)  as  Class;
switch (myMediatorClass.NAME) {
case BasicMediator.NAME :
case EventMediator.NAME :
facade.registerMediator(new myMediatorClass(myComponent.id,myComponent));
}

I think I am still saving quite some lines here, especially given that a project can have a fir mount of mediators and components.

If you want to get a bit more chat on this one, read my conversation with the nice guys at actionscript.org

PureMVC – a few tips

Saturday, October 24th, 2009

Just in case someone else is having the same issues solving coding problems with PureMVC, which is some darn great core for any application, here are my musings:

Re-using Mediators

I used PureMVC to recreate my existing AS2 framework, which means my mediators don’t know in detail, when and how many are used, etc. And for re-usablity reasons, I have to re-name them to establish a unique identifier. For example: all my static components pretty much just need one mediator which initializes the component, can switch them on/off and change layout, etc.

To make it short: one mediator for any number of text components. Unique identifiers for each mediator.

PureMVC’s elements(mediators, proxies) are using two ways to identify themselves, NAME and proxy/mediatorName, the latter is changeable, so there is your way to rename it.