AS3 Condicional Switch Stament

Imaginemonoss que pudiesemos utilizar un switch stament utilizando operadores logicos en vez de operadores de igualdad.

De esta manera podriamos tener un codigo parecido al siguiente:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var value:int = 2;
switch(value){
    case < 1:
        trace("Value is less than 1");
        break;
    case 2:
        trace("Value definitely equals 2");
        break;
    case >= 3:
        trace("Value is greater than or equal to 3");
        break;
    case > 1 && < 3:
        trace("Value is greater than 3 and less than 5");
        break;
    case !== 5:
        trace("Value definitely doesn't equal 5");
        break;
}

Buscando por la red encontre esta solucion:

1
2
3
4
5
6
7
8
9
10
11
12
var value:int = 2;
switch (true) {
    case value < 1:
        trace("Value is less than 1");
    break;
    case value == 1:
        trace("Value equals 1");
    break;
    case value > 1:
        trace("Value is greater than 1");
    break;
}

ZaaIL Soporte +40 formatos de imagen en Flash

De la mano de ZaaLabs, encontramos esta libreria desarrollada en flash que nos permite cargar hasta 40 formatos de imagen en flash.

La verdad es que estos tios se lo han currado, han portado una libreria existente en C llamada DevIL con la ayuda de la tecnologia Alchemy de flash.

Más Info:Zaalabs
Download:ZaaIL

Formatos Soportados

  • Blizzard game textures – .blp
  • Windows Bitmap – .bmp
  • Multi-PCX – .dcx
  • DirectDraw Surface – .dds
  • Dicom – .dicom, .dcm
  • Flexible Image Transport System – .fits, .fit
  • Graphics Interchange Format – .gif
  • Radiance High Dynamic – .hdr
  • Macintosh icon – .icns
  • Windows icon/cursor – .ico, .cur
  • Interchange File Format – .iff
  • Interlaced Bitmap – .lbm, .ilbm
  • Infinity Ward Image (doesn’t work with MW2 iwi files) – .iwi
  • Jpeg – .jpg, .jpe, .jpeg
  • Jpeg 2000 – .jp2
  • Homeworld texture – .lif
  • Half-Life Model – .mdl
  • MPEG-1 Audio Layer 3 (Amazon MP3s work, Apple’s do not) – .mp3
  • Kodak PhotoCD – .pcd
  • ZSoft PCX – .pcx
  • Softimage PIC – .pic
  • Alias | Wavefront – .pix
  • Portable Network Graphics – .png
  • Portable Anymap – .pbm, .pgm, .pnm, .pnm
  • Adobe PhotoShop – .psd
  • PaintShop Pro – .psp
  • Pixar – .pxr
  • Raw data – .raw
  • Homeworld 2 Texture – .rot
  • Silicon Graphics – .sgi, .bw, .rgb, .rgba
  • Sun Microsystems, .sun
  • Creative Assembly Texture – .texture
  • Truevision Targa – .tga
  • Tagged Image File Format – .tif
  • Gamecube Texture – .tpl
  • Unreal Texture – .utx
  • Valve Texture Format – .vtf
  • Game Archive – .wad
  • Quake 2 Texture – .wal
  • Wireless Bitmap File Format – .wbmp
  • HD Photo – .wdp, .hdp
  • X Pixel Map – .xpm
  • Doom Graphics

Como crear dinamicamente instancias de la clase Vector

AS3 no nos permite nativamente crear instancias de la clase vector de forma dinamica, la solucion de nuevo nos viene dada por getDefinitionByName.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package
{
    import flash.system.ApplicationDomain;
    import flash.utils.getQualifiedClassName;  

    public class ClassUtils
    {
        static private const  VECTOR_CLASS_NAME : String = getQualifiedClassName( Vector );

        static public function getVectorDefinition(itemDefinition : Class, applicationDomain : ApplicationDomain = null) : Class
        {
            if(!applicationDomain) applicationDomain = ApplicationDomain.currentDomain;
            return applicationDomain.getDefinition( VECTOR_CLASS_NAME + '.<' + getQualifiedClassName( itemDefinition ) + '>' ) as Class;
        }      
        static public function createCustomVector(itemDefinition : Class, length : uint = 0, fixed : Boolean = false, applicationDomain : ApplicationDomain = null) : Vector.<*>
        {
            var definition : Class = getVectorDefinition( itemDefinition, applicationDomain );
            return new definition( length, fixed );
        }      
    }
}

Para obtener una definicion de vector del tipo especificado utilizaremos:

1
2
3
4
var itemType:Class = Sprite;
var definition:Class = ClassUtils.getVectorDefinition(itemType);
trace(definition); // [class Vector.<flash.display::Sprite>]
trace(getQualifiedClassName(definition)); // __AS3__.vec::Vector.<flash.display::Sprite>

Y para crear una instancia de vector del tipo especificado utilizaremos:

1
2
3
var itemType:Class = Sprite;
var vector:Vector.<*> = ClassUtils.createCustomVector(itemType);
trace(getQualifiedClassName(vector)); // __AS3__.vec::Vector.<flash.display::Sprite>