Comunidad de diseño web y desarrollo en internet online

currentState desde un Tree

Citar            
MensajeEscrito el 22 Jun 2007 03:47 pm
Encuentro muy útil lo de los States de Flex, sin embargo me gustaria que me ayudaran a saber como llamar a un State, desde un Tree, ya que como saben el Tree, obtiene los @label de un XMLList.

Ya se hacerlo con un boton es click=currentState'mistate' pero no se como hacerlo en un Tree.

Espero que me puedan ayudar.

Gracias.

Por jledesma

15 de clabLevel



 

msie7
Citar            
MensajeEscrito el 25 Jun 2007 12:37 pm
Pues igual que lo haces en el botón, evento={currentState='nombreDeEstado'}
Aquí tienes un ejemplo:

Código :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
   <mx:states>
      <mx:State name="tuEstado">
         <mx:AddChild position="lastChild">
            <mx:Button x="68" y="10" label="ok"/>
         </mx:AddChild>
         <mx:AddChild position="lastChild">
            <mx:Button x="68" y="40" label="cancel"/>
         </mx:AddChild>
      </mx:State>
   </mx:states>
   <mx:Tree change="{currentState='tuEstado'}">
      <mx:dataProvider>
         <mx:Array>
            <mx:String>uno</mx:String>
            <mx:String>dos</mx:String>
            <mx:String>tres</mx:String>
         </mx:Array>
      </mx:dataProvider>
   </mx:Tree>
   
</mx:Application>


Si necesitas que vaya a un estado determinado, crea una función que se invoque con el evento, y contrólalo de allí.

Por Zah

BOFH

4290 de clabLevel

27 tutoriales
5 articulos

  Bastard Operators From Hell Editores

Zaragoza, España

firefox
Citar            
MensajeEscrito el 25 Jun 2007 03:21 pm
el problema es que soy muy nuevo en Flex y no se como se hace la funcion.
Yo tengo mi XMLList, así:

<mx:XMLList id="treeUno">
<node label="Principal">
<node label="Uno"/>
<node label="Dos"/>
<node label="Tres"/>
</node>
</mx:XMLList>

Luego tengo mi tree asi:

<mx:Tree id="primertree" width="209" height="249" labelField="@label" showRoot="false" dataProvider="{treeUno}"/>

si yo le pongo click="currentState='state1'" si va al State, pero no importa en cual label le de click, ahora bien, lo que yo quiero es aprender como hacer la función para poder ir a un State diferente, dependiendo del label.

Gracias de antemano, y disculpa que aún no sepa como hacer la función.

Por jledesma

15 de clabLevel



 

msie7
Citar            
MensajeEscrito el 25 Jun 2007 06:31 pm
Dale un propiedad "data" con el nombre del estado al que quieras ir (ten en cuenta que el estado inicial es una cadena vacía "") a cada uno de los elementos del dataProvider.
Aquí lo tienes:

Código :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
   <mx:states>
      <mx:State name="state1">
         <mx:AddChild position="lastChild">
            <mx:Button x="68" y="10" label="ok"/>
         </mx:AddChild>
         <mx:AddChild position="lastChild">
            <mx:Button x="68" y="40" label="cancel"/>
         </mx:AddChild>
      </mx:State>
      <mx:State name="state2" basedOn="state1">
         <mx:AddChild position="lastChild">
            <mx:CheckBox x="68" y="70" label="Checkbox"/>
         </mx:AddChild>
      </mx:State>
      <mx:State name="state3" basedOn="state2">
         <mx:AddChild position="lastChild">
            <mx:ColorPicker x="68" y="96"/>
         </mx:AddChild>
      </mx:State>
   </mx:states>
   <mx:ArrayCollection id="arr">
      <mx:source>
         <mx:Object label="uno" data=""/>
         <mx:Object label="dos" data="state2"/>
         <mx:Object label="tres" data="state3"/>   
      </mx:source>
   </mx:ArrayCollection>
   <mx:Tree id="tuTree" change="{currentState=tuTree.selectedItem.data}" dataProvider="{arr}">
   </mx:Tree>
   
</mx:Application>

Ten en cuenta que el origen de datos de los componentes es un ArrayCollection (también un array pero es peor). El XMLList existe simplemente por compatibilidad con AS2, pero en la práctica, no tiene utilidad.

Por Zah

BOFH

4290 de clabLevel

27 tutoriales
5 articulos

  Bastard Operators From Hell Editores

Zaragoza, España

firefox
Citar            
MensajeEscrito el 25 Jun 2007 08:50 pm

Código :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" height="387" width="536">
   <mx:states>
      <mx:State name="state2">
         <mx:AddChild relativeTo="{paneluno}" position="lastChild">
            <mx:DataGrid x="0" y="0" width="289" height="322">
               <mx:columns>
                  <mx:DataGridColumn headerText="Column 1" dataField="col1"/>
                  <mx:DataGridColumn headerText="Column 2" dataField="col2"/>
                  <mx:DataGridColumn headerText="Column 3" dataField="col3"/>
               </mx:columns>
            </mx:DataGrid>
         </mx:AddChild>
         <mx:SetProperty target="{paneluno}" name="title" value="prueba1\State2"/>
      </mx:State>
   </mx:states>
   <mx:XMLList id="treeUno">
       <node label="Uno">
            <node label="subUno"/>
           <node label="subDos"/>
           <node label="subTres" >
              <node label="subTresUno"/>
              <node label="subTresDos"/>
              <node label="subTresTres"/>
           </node>
      </node>   
    </mx:XMLList>
    <mx:Panel 
      x="217"
      y="0"
      width="309"
      height="362"
      layout="absolute"
      title="prueba1"
      id="paneluno"
      status="Copyright © 2007">
   </mx:Panel>
      <mx:Tree 
          id="mytree"
          width="209" height="362"
          labelField="@label"
          showRoot="false"
          dataProvider="{treeUno}"/>
</mx:Application>


Este es mi codigo, haber si me puedes ayudar y disculpa las molestias.

Por jledesma

15 de clabLevel



 

msie7
Citar            
MensajeEscrito el 25 Jun 2007 08:53 pm
El problema es que necesito usar sub carpetas y a como tú me lo indicas en el ejercicio anterior no pude crear las subcarpetas.

Por jledesma

15 de clabLevel



 

msie7
Citar            
MensajeEscrito el 26 Jun 2007 03:25 pm
Encontre un script que te permite hacerlo desde un XMLList, pero no entiendo bien la funcion.

Código :

<mx:Script>
        <![CDATA[
            [Bindable]
            public var selectedNode:XML;
            public function treeChanged(event:Event):void {
               selectedNode=Tree(event.target).selectedItem as XML
            }
        ]]>
    </mx:Script>

Me supongo que se debe hacer algo semejante, espero que me puedas ayudar.

Gracias.

Por jledesma

15 de clabLevel



 

msie7
Citar            
MensajeEscrito el 28 Jun 2007 12:18 pm
Perdona por tardar tanto en responder. No era para nada como yo pensaba...

Código :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" height="387" width="536">
   <mx:states>
      <mx:State name="state2">
         <mx:AddChild relativeTo="{paneluno}" position="lastChild">
            <mx:DataGrid x="0" y="0" width="289" height="322">
               <mx:columns>
                  <mx:DataGridColumn headerText="Column 1" dataField="col1"/>
                  <mx:DataGridColumn headerText="Column 2" dataField="col2"/>
                  <mx:DataGridColumn headerText="Column 3" dataField="col3"/>
               </mx:columns>
            </mx:DataGrid>
         </mx:AddChild>
         <mx:SetProperty target="{paneluno}" name="title" value="prueba1\State2"/>
      </mx:State>
   </mx:states>
   <mx:Script>
      <![CDATA[
      import mx.collections.ArrayCollection;
         public function onChange(ev:Event):void
         {
            if(ev.currentTarget.selectedItem.@iraestado){
               currentState=ev.currentTarget.selectedItem.@iraestado
            }
         }
      ]]>
   </mx:Script>

    <mx:Panel 
      x="217"
      y="0"
      width="309"
      height="362"
      layout="absolute"
      title="prueba1"
      id="paneluno"
      status="Copyright © 2007">
   </mx:Panel>
      <mx:Tree id="mytree" width="209" height="362" labelField="@label" showRoot="false"
           change="onChange(event)">
         <mx:XMLListCollection id="list">
         <mx:XMLList>
             <node label="Uno">
            <node label="subUno"/>
           <node label="subDos" iraestado="state2"/>
           <node label="subTres" >
              <node label="subTresUno"/>
              <node label="subTresDos"/>
              <node label="subTresTres"/>
           </node>
      </node>   
         </mx:XMLList>
            
         </mx:XMLListCollection>     
           
      </mx:Tree>
</mx:Application>

Por Zah

BOFH

4290 de clabLevel

27 tutoriales
5 articulos

  Bastard Operators From Hell Editores

Zaragoza, España

firefox
Citar            
MensajeEscrito el 28 Jun 2007 08:06 pm
Gracias, tu si sabes.

Espero en el futuro poder contribuir a este foro.

Por jledesma

15 de clabLevel



 

msie7

 

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