Capitulos de este wiki
  1. 1 AS3 / Flex2 Arrays tipados

AS3 / Flex2 Arrays tipados - AS3 / Flex2 Arrays tipados

1 - AS3 / Flex2 Arrays tipados

Tutorial creado por joangarnet. Extraido de: http://www.joangarnet.com/blog/?p=354
19 de Septiembre de 2006

Dos posibles soluciones al tipado fuerte para arrays ( TypedArray )

Flex2:

PLAIN TEXT
JAVA:
  1. [ArrayElementType("String")]
  2. public var newStringProperty:Array;

Flex2 / AS3:

PLAIN TEXT
JAVA:
  1. // sacado de: http://livedocs.macromedia.com/labs/as3preview/docs/00000087.html#120171
  2. package
  3. {
  4.     public dynamic class TypedArray extends Array
  5.     {
  6.         private var dataType:Class;
  7.        
  8.         public function TypedArray ( typeParam:Class, ...args )
  9.         {
  10.             dataType = typeParam;
  11.             var n:uint = args.length
  12.             if (n == 1 && (args[0] is Number))
  13.             {
  14.                 var dlen:Number = args[0];
  15.                 var ulen:uint = dlen
  16.                 if (ulen != dlen)
  17.                 {
  18.                     throw new RangeError("Array index is not a 32-bit unsigned integer ("+dlen+")");
  19.                 }
  20.                 length = ulen;
  21.             }
  22.             else
  23.             {
  24.                 for (var i:int=0; i <n; i++)
  25.                 {
  26.                     // type check done in push()
  27.                     this.push(args[i])
  28.                 }
  29.                 length = this.length;
  30.             }
  31.         }
  32.  
  33.         AS3 override function concat(...args):Array
  34.         {
  35.             var passArgs:TypedArray = new TypedArray(dataType);
  36.             for (var i:* in args)
  37.             {
  38.                 // type check done in push()
  39.                 passArgs.push(args[i]);
  40.             }
  41.             return (super.concat.apply(this, passArgs));
  42.         }
  43.  
  44.         AS3 override function push(...args):uint
  45.         {
  46.             for (var i:* in args)
  47.             {
  48.                 if (!(args[i] is dataType))
  49.                 {
  50.                     args.splice(i,1);
  51.                 }
  52.             }
  53.             return (super.push.apply(this, args));
  54.         }
  55.  
  56.         AS3 override function splice(...args):*
  57.         {
  58.             if (args.length> 2)
  59.             {
  60.                 for (var i:int=2; i<args.length; i++)
  61.                 {
  62.                     if (!(args[i] is dataType))
  63.                     {
  64.                         args.splice(i,1);
  65.                     }
  66.                 }
  67.             }
  68.             return (super.splice.apply(this, args));
  69.         }
  70.  
  71.         AS3 override function unshift(...args):uint
  72.         {
  73.             for (var i:* in args)
  74.             {
  75.                 if (!(args[i] is dataType))
  76.                 {
  77.                     args.splice(i,1);
  78.                 }
  79.             }
  80.             return (super.unshift.apply(this, args));
  81.         }
  82.     }
  83. }

Sé el primero en opinar


Tutoriales relacionados con 'AS3 / Flex2 Arrays tipados'

Dos posibles soluciones al tipado fuerte para arrays ( TypedArray )

Autor y licencia de 'AS3 / Flex2 Arrays tipados'


Tutorial de joangarnet. Extraido de: http://www.joangarnet.com/blog/?p=354 CopyLeft
Este contenido ha sido recopilado por el equipo de Wikilearning. Todo el contenido recopilado se ha obtenido respetando y comunicando en nuestro site la licencia de cada fuente.
Wikilearning tiene permiso expreso por escrito de los autores para publicar los contenidos que ha extraído de otras webs, incluyendo su uso comercial.