Comunidad de diseño web y desarrollo en internet online

acceder a elementos por ID en FLEX

Citar            
MensajeEscrito el 24 Mar 2009 08:31 am
Buenos Dias:
Somos nuevos en esto de flex y estamos haciendo una aplicioncilla pequeñita para ir cogiendo practica.
Estamos creando un grid dinamicamente con actionscript añadiendo filas y celdas.A las celdas y a las filas les ponemos id y name.
Una vez finalizado el dibujo de las celdas tenemos un boton que al pinchar queremos recorrer todas las celdas y ahi viene el problema,no somos capaces de hacerlo por id ni name directamente,en plan getElementById como en javascript,me dicen que no existen si pongo this['celda00]' o this.celda00 me da el mismo error.

Alguna idea ,os pego el codigo

Código :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="top"
        backgroundColor="white"
   creationComplete="llenaGrid(2003,2);" backgroundGradientAlphas="[1.0, 1.0]" 
   backgroundGradientColors="[#3D066B, #EAE0F3]">  
   <mx:Style source="Estilos.css" /> 
<mx:Script>
   <![CDATA[

      import mx.controls.Label;
       import flash.events.MouseEvent;
      import mx.containers.GridRow;
      import mx.containers.GridItem;
      import mx.containers.Grid;
      public  var arrDia:Array=new Array('Lunes','Martes','Miercoles'
                                         ,'Jueves','Viernes','Sabado','Domingo');
        public var arrMes:Array=new Array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio'
                         ,'Julio','Agosto','Septiempbre','Octubre','Noviembre','Diciembre');
     public function doZoom(event:MouseEvent):void {
                if (zoomAll.isPlaying) {
                    zoomAll.reverse();
                }
                else {
                    // If this is a ROLL_OUT event, play the effect backwards. 
                    // If this is a ROLL_OVER event, play the effect forwards.
                    zoomAll.play([event.target], event.type == MouseEvent.ROLL_OUT ? true : false);
                }
            }                               
   public function llenaGrid(ano:Number,m:Number):void{
      //Titulos de dias
       var gr:GridRow = new GridRow();
        gr.height=24;
       for(var i:int=0;i<=6;i++){   
          var gi:GridItem = new GridItem();
          var la:Label=new Label();
          la.text=arrDia[i]; 
          la.width=38;
          la.height=31;          
          gi.width=48;
          gi.height=31;
          gi.id='dia'+i.toString();
          gi.addChild(la);
          gr.addChild(gi);
        }  
       migrid.addChild(gr);
       //a Por los Dias oeoeoe
       var primerDia:Number=Dia(ano,m,1);
       var numeroDi:Number=devuelveNumDias(ano.toString(),m);
        mx.controls.Alert.show('jotaultimo'+numeroDi.toString());
         mx.controls.Alert.show('jotaprimer'+primerDia.toString());
       var tope:int=4;
       var numero:int=1;
       if ((primerDia==5 && numeroDi==31)
           || (primerDia==6  && numeroDi>30)){
            tope=5;
         }
       for (var j:int=0;j<=tope;j++){
           var gr:GridRow=new GridRow();
           gr.id='fila'+j.toString();
           gr.height=24;
           for (var ji:int=0;ji<=6;ji++){
            var gi:GridItem = new GridItem();
          var la:Label=new Label();
          la.width=38;
          la.height=31; 
          if ((j==0 && primerDia>ji)||(numero>numeroDi)) la.text='';             
          else {
            la.text=numero.toString();
            numero++;
          }   
        
          if (ji>=5) la.setStyle('color','red');      
          gi.width=48;
          gi.height=31;
          gi.useHandCursor=true;
          
 gi.buttonMode=true;
 gi.mouseChildren=false;
[color=#EF2929]          gi.id='celda'+j.toString()+ji.toString();//[/color] //aqui me creo la celda y los id.
          gi.name='celda'+j.toString()+ji.toString();
          la.id='label'+j.toString()+ji.toString();
          la.addEventListener(MouseEvent.MOUSE_OVER,doZoom);
          gi.addChild(la);
          gr.addChild(gi);
    
          
          
           }
           migrid.addChild(gr);
           Calendario1.title=arrMes[m]+'-'+ano.toString()
       }
}   
public function Dia(a:Number,m:Number,d:Number):Number{
    var miFecha:Date=new Date(a,m,d);
    var mD:Number=m+1;
    var miFecha1:Date=new Date(a,m,1);
    var miFecha2:Date=new Date(a,mD,1);
    var diaSemana:Number=miFecha.getDay();  
    var aux:Number;
   switch(diaSemana){
      case 0:
       aux=6
       break;
      case 1:
       aux=0
       break;
      case 2:
       aux=1
       break;
      case 3:
       aux=2
       break;
      case 4:
       aux=3
       break;
      case 5:
       aux=4
       break;
      case 6:
       aux=5
       break;     
   }
    return(aux);
}         
public function devuelveNumDias(año:String, mes:Number):Number {
       var diaUltimo:Date = new Date(año, mes, 31); 
       mx.controls.Alert.show('iker'+diaUltimo.toString());
       var numeroDias:Number;
       if (diaUltimo.getMonth() == mes) {
           numeroDias = 31;
       } else {
          mx.controls.Alert.show('gggg'+diaUltimo.getDate());
           numeroDias = 31 - diaUltimo.getDate()
       }
       return numeroDias;
}   

public function Aleale():void{
[color=red] mx.controls.Alert.show(this['celda00'].toString());[/color] //aqui esta el error 
}
   ]]>
</mx:Script>

       
<mx:Panel x="44" y="135" width="387" height="242" layout="absolute" 
         title="" id='Calendario1' horizontalScrollPolicy="off" verticalScrollPolicy="off">        
<mx:Grid id="migrid"  horizontalGap="2" verticalGap="2"  x="7" y="4">
</mx:Grid>
</mx:Panel>
   <mx:Button label="Button" click='Aleale()'/>
</mx:Application>

Por ibi

2 de clabLevel



 

msie
Citar            
MensajeEscrito el 24 Mar 2009 11:01 am
Cuando usas componentes (y en Flex lo harás todo el tiempo), consulta siempre los métodos del componente en cuestión, en el caso de un datagrid, la forma mas fácil es usar un ArrayCollection como dataprovider, y luego recorrerlo en un loop usando getItemAt

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 25 Mar 2009 10:31 am
Muchas Gracias Jorge!

Por ibi

2 de clabLevel



 

msie

 

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