Comunidad de diseño web y desarrollo en internet online

Como usar un ArrayCollection

Citar            
MensajeEscrito el 21 May 2009 03:29 pm
Hola, no consigo utilizar correctamente un ArrayCollection, cargar datos y usarlo como DataProvider.
Usando la solución cutre me funciona, que sería:


<mx:Label text="{num1}" width="20" x="28"/>
<mx:Label text="{num2}" width="20" x="107" />
<mx:Label text="{num3}" width="20" x="199" y="3"/>

Código :

<mx:Script>
<![CDATA[
public var _estadistica:Array = new Array();

[Bindable]
public var num1:Number;
[Bindable]
public var num2:Number;
[Bindable]
public var num3:Number;

for (var i:Number = 0; i < aux.length(); i++) {
      var tipo:String = aux.@tipo; //Tipo puede tomar 3 posibles valores: "alojamiento, "monumentos", u "ocio"
      _estadistica['tipo']++;
}
      
              
num1=_estadistica["alojamiento"];
num2=_estadistica["monumentos"];
num3=_estadistica["ocio"];

]]> 
</mx:Script>


Lo que pasa que quiero hacerlo sin tener que recurrir a num1, num2, num3.
Pero no puedo pasar directamente el vector _estadistica[ ] como DataProvider porque Flex me lanza un warning avisando de que tengo que usar ArrayCollection en vez de Array como DataProvider.

Alguien puede "transformar" ese código a otro con un ArrayCollection y sin num1, num2, num2 o explicarme cómo hacerlo? Lo he intentando varias veces pero no me aclaro con el ArrayCollection.

Gracias, un saludo.

Por riestra

73 de clabLevel



 

firefox
Citar            
MensajeEscrito el 21 May 2009 04:29 pm
Voy a refinarlo un poco más.

Lo que no tengo claro del ArrayCollection es cómo acceder a sus elementos de manera dinámica.

Código :

Si declaro
[Bindable]
public var vect:ArrayCollection;
vect= new ArrayCollection([{'alojamiento':3, 'deportes':2, 'trabajo':1}]);
//vect.getItemAt(0).alojamiento   Asi obtengo el valor de alojamiento.

String tipo="alojamiento";
Como accedo a la posicion alojamiento del ArrayCollection vect usando la variable tipo??
vect.getItemAt(0).tipo  //Así no funciona!!

Con un array seria :

String tipo="alojamiento";
public var _estadistica:Array = new Array();
_estadistica['monumentos']=0;
_estadistica['alojamiento']=0;
_estadistica['ocio']=0;

int valor=_estadistica[tipo];



Como hago eso con el ArrayCollection?
Gracias y un saludo.

Por riestra

73 de clabLevel



 

firefox
Citar            
MensajeEscrito el 21 May 2009 07:06 pm
Pues de la misma forma:

vect.getItemAt(0)[tipo]

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 21 May 2009 07:46 pm
Pero si lo hago de la misma forma no puedo usarlo en el DataProvider. Por eso flex me lanza el warning y me dice que no puedo usar el operador [ ] y que tengo que usar en vez de array ArrayCollection.

Por riestra

73 de clabLevel



 

firefox
Citar            
MensajeEscrito el 21 May 2009 08:38 pm
Solo explico esto:


Como accedo a la posicion alojamiento del ArrayCollection vect usando la variable tipo??
vect.getItemAt(0).tipo //Así no funciona!!


Luego no se cual es tu objetivo

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 21 May 2009 09:07 pm
Mi objetivo es
¿cómo utilizo un ArrayCollection como DataProvider de varios controles Label para no tener que hacer lo que he expuesto en mi segundo post:

Código :

num1=_estadistica["alojamiento"];
num2=_estadistica["monumentos"];
num3=_estadistica["ocio"];



<mx:Label text="{num1}" width="20" x="28"/>
<mx:Label text="{num2}" width="20" x="107" />
<mx:Label text="{num3}" width="20" x="199" y="3"/>


NO puedo hacer lo siguiente, da error en Flex.
<

Código :

mx:Label text="{_estadistica["alojamiento"]}" width="20" x="28"/>
<mx:Label text="{_estadistica["monumentos"]}" width="20" x="107" />
<mx:Label text="{_estadistica["ocio"]}" width="20" x="199" y="3"/>

Por riestra

73 de clabLevel



 

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.