0 Replies Latest reply on Apr 5, 2010 11:09 AM by Gamaliel Arredondo Montes

    Values dinamically with custom components

    Gamaliel Arredondo Montes

      Hi everyone, i have a problem with flex, i developed a main aplication in witch i have added a container (sesionGroup), also i did a custom component witch contains one button and one label. the main application creates several components dinamically using the custom component with values assigned dinamically by an external xml file, this is the code of the main application:

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:mx="library://ns.adobe.com/flex/halo"
      minWidth="1024" minHeight="768"
      creationComplete="init()">

      <fx:Declarations>
      <s:HTTPService id="sesionService" url="PHPClases/sesiones.php"
      resultFormat="object"  result="sesionService_resultHandler(event)"/>
      </fx:Declarations>

      <fx:Script>
      <![CDATA[
      import mx.collections.ArrayCollection;
      import mx.controls.Alert;
      import mx.rpc.events.ResultEvent;

      import spark.components.VGroup;


      public var grupoSesion:sesion;
      public var cont:int=0;
      [Bindable]
      public var sesionDatos:ArrayCollection;

      public function init():void
      {
      sesionService.send();
      }


      protected function sesionService_resultHandler(event:ResultEvent):voi   d
      {
      sesionDatos=event.result.sesiones.sesion;
      var i:int=event.result.sesiones.sesion.getItemAt(0).fi  las;
      while(cont<i)
      {
      grupoSesion=new sesion();
      grupoSesion.nombreSesion=event.result.sesiones.ses   ion.getItemAt(cont).nombre;
      grupoSesion.indexSesion=cont.toString();
      grupoSesion.name=cont.toString();
      grupoSesion.addEventListener(MouseEvent.CLICK,most  rarEventos);
      sesionGroup.addElementAt(grupoSesion,cont);
      cont++;
      }
      }

      public function mostrarEventos(event:MouseEvent):void
      {
      Alert.show();
      }

      ]]>
      </fx:Script>

      <s:VGroup id="sesionGroup" x="270" y="150">
      <s:Label id="prueba"/>
      </s:VGroup>

      </s:Application>

      And this is the code of the custom component

      <?xml version="1.0" encoding="utf-8"?>
      <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:mx="library://ns.adobe.com/flex/halo" width="400"  height="20">

      <fx:Script>
      <![CDATA[

      [Bindable]
      public var nombreSesion:String;
      [Bindable]
      public var indexSesion:String;

      ]]>
      </fx:Script>

      <s:Button id="sesionButton"
      label="{nombreSesion}"/>
      <s:Label text="{indexSesion}"/>

      </s:Group>

       

      Like you can see i have added for each component one event clic, and i want that when a user clic one component the red alert of the main aplication shows him the value of the selected component, for example, if a user clic the first component it must show 0 (or 1), if the user clic the second component it must show 1 (or 2), etc. I have found other ways like getChilindex and others but those give me the same result for all the components, the value of the first or the last component.

       

      If you can help me i thank you much, and thanks for your attention.