Comunidad de diseño web y desarrollo en internet online

canvas en flex

Citar            
MensajeEscrito el 09 Ene 2009 04:25 am
hola alguien me puede decir como puedo actualizar un contenido de un canvas
saludos

Por anikilatorbeta

42 de clabLevel



 

firefox
Citar            
MensajeEscrito el 09 Ene 2009 10:00 am
¿Republicando? Explícate

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 09 Ene 2009 01:08 pm
lo que pasa q a ese canvas le hago un removeAllChildren(); pq necesito sacar todo el contenido y actualizarlo por otro y luego conn un addChild(); le agrego el otro contenido pero el nuevo contenio no apareci si no q queda todo en blanco

esta es la funcion

Código ActionScript :

private function llenado_grupos(inicio:int,fin:int):void{
         var tem_form:Form=new Form();
         if(inicio!=1){
            layer_grupos.removeAllChildren();
         }
         tem_num_fin=inicio+14;
         if(fin<tem_num_fin){
            tem_num_fin=fin;
         }
         //tem_form.name="form_grupo_0";   
         //carga de text input grupos
         for(var a:int=inicio;a<tem_num_fin;a++)
         {
            var tem_num:int=a+1;
            var tem_formitem:FormItem=new FormItem();
            var tem_texinput:TextInput=new TextInput();
            tem_formitem.name="form_grupos_"+a;
            tem_formitem.label="grupos "+tem_num;
            tem_texinput.name="txt_grupos_"+a;
            tem_formitem.addChild(tem_texinput);
            tem_form.addChild(tem_formitem);
         }
            if(fin!=tem_num_fin){
               var tem_boton:Button=new Button();
               tem_boton.label="siguiente";
               tem_boton.addEventListener(MouseEvent.CLICK, click_grupo);
               tem_form.addChild(tem_boton);
            }
            layer_grupos.addChild(tem_form);
      }


[BOFH]Usa tags as para el código[/BOFH]

Por anikilatorbeta

42 de clabLevel



 

firefox
Citar            
MensajeEscrito el 09 Ene 2009 01:23 pm
Es mas simple usar estados ... pero bueno. Lo primero es ver si lo agrega (y no se ve) o no lo agrega. ¿Que pasa si trazas layer_grupos.numChildren después de agregarlo?

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 09 Ene 2009 02:12 pm
nop no funciona aqui te dejo el codigo completo

Código :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientAlphas="[1.0, 1.0]" initialize="init();" backgroundGradientColors="[#632626, #632626]" viewSourceURL="srcview/index.html"  height="650">
<mx:Script>
   <![CDATA[
      import mx.accessibility.ButtonAccImpl;
      import mx.binding.utils.BindingUtils;
      import mx.collections.ArrayCollection;
      import mx.controls.ComboBox;
      import mx.controls.Label;
      import mx.containers.FormItem;
      import mx.controls.Alert;
      import mx.events.ValidationResultEvent;
      import mx.controls.Button;
      import mx.controls.TextInput;
      private var fin:int;
      private var algo:int;
      private var tem_num_fin:int=0;
      private var ar_grupos:ArrayCollection=new ArrayCollection();
      private var ar_sub_grupos:ArrayCollection=new ArrayCollection();
      private var ar_lista:ArrayCollection=new ArrayCollection();
      [Bindable]
      private var combo_fac_grupo:ClassFactory;
      private var combo_fac_sub_grupo:ClassFactory;
      private function init():void{
         combo_fac_grupo=new ClassFactory(ComboBox);
         combo_fac_grupo.properties={dataProvider:ar_grupos};
         combo_fac_sub_grupo=new ClassFactory(ComboBox);
         combo_fac_sub_grupo.properties={dataProvider:ar_sub_grupos};
      }
      private function init_layer_grupos():void{
      llenado_grupos(tem_num_fin,parseInt(num_grupos.text));
      }
      
      private function llenado_grupos(inicio:int,fin:int):void{
         //creacion de canvas
         var tem_form:Form=new Form();
         algo=layer_grupos.numChildren;
         if(inicio!=1){
            layer_grupos.removeAllChildren();
         }
         tem_num_fin=inicio+14;
         if(fin<tem_num_fin){
            tem_num_fin=fin;
         }
         //tem_form.name="form_grupo_0";   
         //carga de text input grupos
         for(var a:int=inicio;a<tem_num_fin;a++)
         {
            var tem_num:int=a+1;
            var tem_formitem:FormItem=new FormItem();
            var tem_texinput:TextInput=new TextInput();
            tem_formitem.name="form_grupos_"+a;
            tem_formitem.label="grupos "+tem_num;
            tem_texinput.name="txt_grupos_"+a;
            tem_formitem.addChild(tem_texinput);
            tem_form.addChild(tem_formitem);
         }
            if(fin!=tem_num_fin){
               var tem_boton:Button=new Button();
               tem_boton.label="siguiente";
               tem_boton.addEventListener(MouseEvent.CLICK, click_grupo);
               tem_form.addChild(tem_boton);
            }
            layer_grupos.addChild(tem_form);
            algo=layer_grupos.numChildren;
      }
      private function click_grupo(e:MouseEvent):void{
         llenado_grupos(tem_num_fin,fin);
         //layer_grupos.updateCompletePendingFlag
      }
      private function init_layer_grup():void{
         
         //carga de text input sub grupos
         for(var a:int=0;a<parseInt(num_sub_grupos.text);a++)
         {
            var tem_num:int=a+1;
            var tem_formitem:FormItem=new FormItem();
            var tem_texinput:TextInput=new TextInput();
            tem_formitem.name="form_sub_grupos_"+a;
            tem_formitem.label="Sub Grupos "+tem_num;
            tem_texinput.name="txt_sub_grupos_"+a;
            tem_formitem.addChild(tem_texinput);
            layer_sub_grupos.addChild(tem_formitem);
         }
      }
      private function llenado():void{
         //llenado combobox grupos
         for(var a:int=0;a<parseInt(num_grupos.text);a++){
            var tem_formitem:FormItem=new FormItem();
            var tem_texinput:TextInput=new TextInput();
            tem_formitem= layer_grupos.getChildByName("form_grupos_"+a)as FormItem;
            tem_texinput= tem_formitem.getChildByName("txt_grupos_"+a)as TextInput;
            ar_grupos.addItem({id:a,label:tem_texinput.text});
         }
         //llenado combobox sub grupos
         for(var a:int=0;a<parseInt(num_sub_grupos.text);a++){
            var tem_formitem:FormItem=new FormItem();
            var tem_texinput:TextInput=new TextInput();
            tem_formitem= layer_sub_grupos.getChildByName("form_sub_grupos_"+a)as FormItem;
            tem_texinput= tem_formitem.getChildByName("txt_sub_grupos_"+a)as TextInput;
            ar_sub_grupos.addItem({id:a,label:tem_texinput.text});
         }
      }
      private function init_layer_usuarios():void{
         //llenado de usuarios
         var y:int=0;
         for(var a:int=0;a<parseInt(num_usuarios.text);a++){
            var tem_num:int=a+1;
            //ini label
            var tem_label:Label=new Label();
            tem_label.text="Usuario "+tem_num+":";
            tem_label.move(10,y);
            layer_usuarios.addChild(tem_label);
            //fin label         
            //ini textinput
            var tem_texinput:TextInput=new TextInput();
            tem_texinput.name="usuario_"+a
            tem_texinput.move(80,y);
            layer_usuarios.addChild(tem_texinput);
            //fin textinput
            //ini combobox grupos
            var tem_combobox_grupos:ComboBox=new ComboBox();
            tem_combobox_grupos.name="grupos_"+a;
            tem_combobox_grupos.dataProvider=ar_grupos;
            tem_combobox_grupos.move(250,y);
            layer_usuarios.addChild(tem_combobox_grupos);
            //fin combobox grupos
            //ini combobox sub grupos
            var tem_combobox_sub_grupos:ComboBox=new ComboBox();
            tem_combobox_sub_grupos.name="sub_grupos_"+a;
            tem_combobox_sub_grupos.dataProvider=ar_sub_grupos;
            tem_combobox_sub_grupos.move(420,y);
            layer_usuarios.addChild(tem_combobox_sub_grupos);
            //fin combobox sub grupos
            y=y+30;
         }
      }
      private function init_layer_listado():void{
         for(var a:int=0;a<parseInt(num_usuarios.text);a++){
            //sacar datos nombre usuario
            var tem_texinput:TextInput=new TextInput();
            tem_texinput=layer_usuarios.getChildByName("usuario_"+a)as TextInput;
            //sacar datos grupo
            var tem_combo_grupo:ComboBox=new ComboBox();
            tem_combo_grupo=layer_usuarios.getChildByName("grupos_"+a)as ComboBox;
            //sacar datos sub grupos
            var tem_combo_sub_grupo:ComboBox=new ComboBox();
            tem_combo_sub_grupo=layer_usuarios.getChildByName("sub_grupos_"+a)as ComboBox;
            //traspaso a array collection
            ar_lista.addItem({usuario:tem_texinput.text, grupo:tem_combo_grupo.selectedLabel, sub_grupo:tem_combo_sub_grupo.selectedLabel});
         }
         data_lista.dataProvider=ar_lista;
      }
      private function ir_user():void{
         layer_con.selectedIndex=3;
      }
      private function validar_user():void{
         layer_con.selectedIndex=4;
      }
      private function validar_grup():void{
         layer_con.selectedIndex=2;
      }
      private function validarcantidades():void{
         var validar_usuarios:ValidationResultEvent=validar_usuarios.validate();
         var validar_grupos:ValidationResultEvent=validar_grupos.validate();
         var validar_sub_grupos:ValidationResultEvent=validar_sub_grupos.validate();
         
         if(validar_usuarios.type == ValidationResultEvent.VALID && validar_grupos.type == ValidationResultEvent.VALID && validar_sub_grupos.type == ValidationResultEvent.VALID)
         {
            layer_con.selectedIndex=1;
         }else{
            Alert.show("Faltan Datos Por Ingresar");
         }
      }
   ]]>
</mx:Script>
<mx:StringValidator source="{num_usuarios}" property="text" requiredFieldError="Complete Cantidad de Usuarios" 
   trigger="{btn_can}" triggerEvent="click" id="validar_usuarios"/>
<mx:StringValidator source="{num_grupos}" property="text" requiredFieldError="Complete Cantidad de Grupos" 
   trigger="{btn_can}" triggerEvent="click" id="validar_grupos" />
<mx:StringValidator source="{num_sub_grupos}" property="text" requiredFieldError="Complete Cantidad de Sub Grupos" 
   trigger="{btn_can}" triggerEvent="click" id="validar_sub_grupos"/>
   <mx:TabNavigator width="685" height="544" horizontalCenter="0" verticalCenter="0" selectedIndex="0" id="layer_con">
      <mx:Form label="Inicio" width="100%" height="100%">
         <mx:FormHeading label="Cantidades"/>
         <mx:FormItem label="Usuarios">
            <mx:TextInput restrict="0-9" id="num_usuarios"/>
         </mx:FormItem>
         <mx:FormItem label="Grupos">
            <mx:TextInput restrict="0-9" id="num_grupos"/>
         </mx:FormItem>
         <mx:FormItem label="Sub Grupos">
            <mx:TextInput restrict="0-9" id="num_sub_grupos"/>
         </mx:FormItem>
         <mx:FormItem>
            <mx:Button label="Aceptar" id="btn_can" click="validarcantidades();"/>
         </mx:FormItem>
         </mx:Form>
      <mx:Canvas label="Grupos - Sub Grupos" width="100%" height="100%" initialize="init_layer_grup()">
         <mx:Canvas x="0" y="0" width="341" height="478" >
            <mx:Label x="153" y="0" text="Grupos" fontWeight="bold" fontSize="12"/>
            <mx:ViewStack x="0" y="19" id="layer_grupos" width="341" height="459" selectedIndex="0" initialize="init_layer_grupos()">
            </mx:ViewStack>
         </mx:Canvas>
         <mx:Form x="342" y="0" width="50%" height="478" id="layer_sub_grupos">
            <mx:FormHeading label="Sub Grupos" textAlign="center"/>
         </mx:Form>
         <mx:Button x="608" y="479" label="Aceptar" click="validar_grup();"/>
      </mx:Canvas>
         <mx:Canvas label="Resumen" width="100%" height="100%" initialize="llenado()">
               <mx:DataGrid x="0" y="38" width="338" height="435" dataProvider="{ar_grupos}" editable="true">
                     <mx:columns>
                           <mx:DataGridColumn headerText="Grupos" dataField="label" />
                     </mx:columns>
               </mx:DataGrid>
               <mx:DataGrid x="337" y="38" width="346" height="435" dataProvider="{ar_sub_grupos}" editable="true">
                     <mx:columns>
                           <mx:DataGridColumn headerText="Sub Grupos" dataField="label"/>
                     </mx:columns>
               </mx:DataGrid>
               <mx:Button x="601" y="479" label="Aceptar" click="ir_user()"/>
               <mx:Label x="241.5" y="10" text="Resumen Grupos, Sub Grupos" fontWeight="bold" fontSize="12"/>
      </mx:Canvas>
      <mx:Canvas label="Usuarios" width="100%" height="100%" initialize="init_layer_usuarios()">
         <mx:Button x="601" y="479" label="Aceptar" click="validar_user();"/>
         <mx:Canvas x="0" y="27" height="444" width="683" id="layer_usuarios">
         </mx:Canvas>
         <mx:Label x="80" y="1" text="Nombre" fontWeight="bold" fontSize="12"/>
         <mx:Label x="250" y="1" text="Grupo" fontWeight="bold" fontSize="12"/>
         <mx:Label x="420" y="1" text="Sub Grupo" fontWeight="bold" fontSize="12"/>
      </mx:Canvas>
      <mx:Canvas label="Resumen" width="100%" height="100%" initialize="init_layer_listado()">
         <mx:DataGrid x="10" y="28" width="663" height="473" id="data_lista" editable="true">
            <mx:columns>
               <mx:DataGridColumn headerText="Usuario" dataField="usuario"/>
               <mx:DataGridColumn headerText="Grupo" dataField="grupo" itemEditor="{combo_fac_grupo}"/>
               <mx:DataGridColumn headerText="Sub Grupo" dataField="sub_grupo" itemEditor="{combo_fac_sub_grupo}"/>
            </mx:columns>
         </mx:DataGrid>
         <mx:Label x="278" y="0" text="Resumen Usuarios" fontWeight="bold" fontSize="12"/>
      </mx:Canvas>
      
   </mx:TabNavigator>
   <mx:TextInput x="510" y="605" id="txt_num"/>
</mx:Application>

Por anikilatorbeta

42 de clabLevel



 

firefox
Citar            
MensajeEscrito el 09 Ene 2009 02:14 pm
Usa estados o un ViewStack. Si quieres agregar directamente elementos, usa UIComponent como tag contenedor

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 09 Ene 2009 02:20 pm
como es eso no entender jejeje si yo estoy todo agragando a un view stack

Por anikilatorbeta

42 de clabLevel



 

firefox
Citar            
MensajeEscrito el 09 Ene 2009 02:26 pm
Traza layer_grupos
Traza trazas layer_grupos.numChildren
Pon lo que sale en la traza

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 09 Ene 2009 02:34 pm
sale primero 0 y despues 1

Por anikilatorbeta

42 de clabLevel



 

firefox
Citar            
MensajeEscrito el 09 Ene 2009 02:37 pm
Si sale 1 después de agregar el form, entonces el problema es que no se ve, no que no se agrega. Si por ejemplo tu Canvas tiene layer absoluto, dale posición x e y. Mira si hay alpha o alguna propiedad que este previniendo que se vea

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 09 Ene 2009 03:14 pm
Seré breve...

Primero, Como estás tratando a tu viewStack, el evento "initialize" no aplica, tendrías que usar el evento "show".

Segundo, El estar creando tantos objetos no es óptimo, y más cuando crear un determinado número de formularios a la vez no es práctico, de hecho solo imagina que el usuario se equivoque en el número de usuarios o de grupos, tendría que volver al formulario inicial y luego, volver a llenar toooda la info.

Tercero, te recomendaría usar un ArrayCollection que almacenara toda la info de usuarios, grupos y subgrupos. Y la edición de esta info la podrías hacer a través de un datagrid lo mas sencillo posible. Y si te gustan tanto los formularios, puedes usar un DataBinding por cada registro seleccionado en el DataGrid con el Form.

Por andresmaro

Claber

981 de clabLevel

3 tutoriales
4 articulos

Genero:Masculino  

America/Bogota

chrome
Citar            
MensajeEscrito el 10 Ene 2009 05:13 am
gracias por tu respuesta andresmaro me intereso bastante lo q me dejiste pero a ver si a ti te dieran un proyecto como este como lo harias exactamente? porfavor :D

Por anikilatorbeta

42 de clabLevel



 

firefox
Citar            
MensajeEscrito el 10 Ene 2009 05:17 am
que he andado buscando la respuesta de como hacer esto sin comer tantos recursos

saludos

Por anikilatorbeta

42 de clabLevel



 

firefox
Citar            
MensajeEscrito el 11 Ene 2009 05:14 pm
Bueno, me extendería mucho diciendo como lo haría "exactamente", entre otras cosas porque no tengo idea del proyecto, sin embargo acá dejo algo que te puede ayudar...

Código :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal"  width="900" height="500"> 
   <mx:Script>
      <![CDATA[
         
         import mx.collections.ArrayCollection;
         
         [Bindable] private var grupos:ArrayCollection = new ArrayCollection();
         
         [Bindable] private var usuarios:ArrayCollection = new ArrayCollection();   
         
         private function addUser():void{
            var usuario:Object = new Object();
            usuario.nombre = usuarioN.text;
            usuario.grupo = usuarioG.selectedLabel;
            
            usuarios.addItem(usuario);
         }
         
      ]]>
   </mx:Script>
   
   <mx:VBox height="100%" width="20%">
      <mx:Form width="100%">
         <mx:FormHeading label="Grupos"/>
         <mx:FormItem  label="Nombre">
            <mx:TextInput id="grupoN"/>
         </mx:FormItem>      
         <mx:FormItem>
            <mx:Button label="Agregar" click="grupos.addItem({nombreGrupo:grupoN.text})"/>
         </mx:FormItem>
      </mx:Form>   
      <mx:List width="100%" dataProvider="{grupos}" height="100%" labelField="nombreGrupo"/>      
   </mx:VBox>
   
   <mx:VBox width="40%" height="100%">
      <mx:Label text="Usuarios"  fontSize="14" fontWeight="bold"/>
      <mx:DataGrid id="dataGridUsuarios" dataProvider="{usuarios}" width="100%" height="100%" />
   </mx:VBox>
   
   <mx:VBox width="20%">
      <mx:Form width="100%">
         <mx:FormHeading label="Nuevo Usuarios"/>
         <mx:FormItem label="Nombre">
            <mx:TextInput id="usuarioN"/>
         </mx:FormItem>      
         <mx:FormItem label="Grupo">
            <mx:ComboBox id="usuarioG" dataProvider="{grupos}" labelField="nombreGrupo" />
         </mx:FormItem>
         <mx:FormItem>
            <mx:Button label="Agregar" click="addUser()"/>
         </mx:FormItem>
      </mx:Form>
   </mx:VBox>   
   
</mx:Application>

Por andresmaro

Claber

981 de clabLevel

3 tutoriales
4 articulos

Genero:Masculino  

America/Bogota

chrome
Citar            
MensajeEscrito el 12 Ene 2009 01:20 pm
muchas gracias ya capte como hacerlo gracias a ti
xauu

Por anikilatorbeta

42 de clabLevel



 

firefox

 

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