Comunidad de diseño web y desarrollo en internet online

MEtodos en en AS

Citar            
MensajeEscrito el 04 Sep 2009 05:07 pm
disculpen amigos tengo una duda sobre lo siguiente estoy hacien una aplicacion flash donde uso el mismo codigo el mismito en varios frame de un capa ..entonces mi pregunta es si puedo este codigo meterlo en un metodo y mandar llamarlo en los demas frames(fotogramas) asi ya no tendria ke pegar el codigo en cad auno de ellos solamente llamar el metodo.. no se si me expliko porfabosr alguien me podria orientar o si existe alguna manera de aserlo lo que yo no kiero esta égar el codigo en cada frame..

para que no pese tanto el archivo

este esmi codigo

Código ActionScript :

con=0;
// -- creo un nuevo objeto XML
miXML = new XML();
// -- ignorar espacios 
miXML.ignoreWhite = true;
miXML.onLoad = function(succes) {
   if (succes) {
      // -- por cada nodo hijo del nodo principal...
      for (var i = 0; i < this.firstChild.childNodes.length; i++) {
         con++;
         // -- delaro una variable que recoje el atributo del nodo (nombre de la imagen)
         idImagen = this.firstChild.childNodes[i].attributes.id;
         // -- creo un clip de película vacio 
         holder_mc = createEmptyMovieClip("holder_mc" + i, i + 100);
         // -- creo un clip de película vacio 
         item = holder_mc.createEmptyMovieClip("diapo" + i, i + 100);
         // --  cargo la imágen el clip vacio
         if (con==1){
            idImagen = this.firstChild.childNodes[i].attributes.id;
            holder_mc._x = 45;
            holder_mc._y = 194;
            holder_mc.onRollOver  =  function(){         
               this._xscale =190;
            this._yscale= 190;
                                       };
                                       
            holder_mc.onRollOut  =  function(){         
               this._xscale =100;
            this._yscale= 100;
                                       };
            holder_mc.onPress  =  function(){
               
               gotoAndPlay(2);               };
            
                  }
         //imagen del telefono
         if (con==2){
            idImagen = this.firstChild.childNodes[i].attributes.id;
            holder_mc._x = 80;
            holder_mc._y = 270;
            
            
                  }
         // imagen usuario         
            if (con==3){
            idImagen = this.firstChild.childNodes[i].attributes.id;
            holder_mc._x = 178;
            holder_mc._y = 207;
            holder_mc.onRollOver  =  function(){         
               this._xscale =190;
            this._yscale= 190;
            
            };
            holder_mc.onRollOut  =  function(){         
               this._xscale =100;
            this._yscale= 100;
            
            };
            holder_mc.onPress  =  function(){   
               gotoAndPlay(3);               
                                    };
                     }
            //imagenTelefono         
            if (con==4){
            idImagen = this.firstChild.childNodes[i].attributes.id;
            holder_mc._x = 205;
            holder_mc._y = 280;
                     }
            //imagenUsuario         
            if (con==5){
            idImagen = this.firstChild.childNodes[i].attributes.id;
            holder_mc._x = 275;
            holder_mc._y = 181;   
            holder_mc.onRollOver  =  function(){         
               this._xscale =190;
            this._yscale= 190;
                                       };
            holder_mc.onRollOut  =  function(){         
               this._xscale =100;
            this._yscale= 100;
                                       };
            holder_mc.onPress  =  function(){      
            
               gotoAndPlay(4);               };
               
                     }
               //imagenTelefono
            if (con==6){
            idImagen = this.firstChild.childNodes[i].attributes.id;
            holder_mc._x = 315;
            holder_mc._y = 160;}
            //imagenUsuario
            if (con==7){
            idImagen = this.firstChild.childNodes[i].attributes.id;
            holder_mc._x = 275;
            holder_mc._y = 260;
            holder_mc.onRollOver  =  function(){         
               this._xscale =190;
            this._yscale= 190;
                                       };
            holder_mc.onRollOut  =  function(){         
               this._xscale =100;
            this._yscale= 100;
                                    };
            holder_mc.onPress  =  function(){         
               gotoAndPlay(5);               };
                     }
         //imagenTelefono
         if (con==8){
            idImagen = this.firstChild.childNodes[i].attributes.id;
            holder_mc._x = 315;
            holder_mc._y = 335;}
         if (con==9){
            idImagen = this.firstChild.childNodes[i].attributes.id;
            holder_mc._x = 424;
            holder_mc._y = 194;
            holder_mc.onRollOver  =  function(){         
               this._xscale =190;
            this._yscale= 190;
                                       };
            holder_mc.onRollOut  =  function(){         
               this._xscale =100;
            this._yscale= 100;
                                    };
            holder_mc.onPress  =  function(){         
               gotoAndPlay(6);               };

            }         
                  
         if (con==10){
            idImagen = this.firstChild.childNodes[i].attributes.id;
            holder_mc._x = 460;
            holder_mc._y = 270;
            }                  
         item.loadMovie(idImagen);
         }
   }
};
//miXML.load("http://localhost/SegHigiene/xml_fotos_SH.php");
miXML.load("http://10.6.2.113/SegHigiene/xml_fotos_estatus_SH.php");
stop();



alguien podra ayudarme

Por carych

37 de clabLevel



 

msie7
Citar            
MensajeEscrito el 05 Sep 2009 12:09 am
no es necesario generar un metodo, ya lo estas haciedo al hacer:

Código ActionScript :

miXML.onLoad = function(succes) 


calculo que el codigo de este es el mismo solo que cambia el:

Código ActionScript :

miXML.load("http://10.6.2.113/SegHigiene/xml_fotos_estatus_SH.php"); 


de ser asi solo deja este codigo en el primer frame:

Código ActionScript :

con=0; 
// -- creo un nuevo objeto XML 
miXML = new XML(); 
// -- ignorar espacios  
miXML.ignoreWhite = true; 
miXML.onLoad = function(succes) { 
   if (succes) { 
      // -- por cada nodo hijo del nodo principal... 
      for (var i = 0; i < this.firstChild.childNodes.length; i++) { 
         con++; 
         // -- delaro una variable que recoje el atributo del nodo (nombre de la imagen) 
         idImagen = this.firstChild.childNodes[i].attributes.id; 
         // -- creo un clip de película vacio  
         holder_mc = createEmptyMovieClip("holder_mc" + i, i + 100); 
         // -- creo un clip de película vacio  
         item = holder_mc.createEmptyMovieClip("diapo" + i, i + 100); 
         // --  cargo la imágen el clip vacio 
         if (con==1){ 
            idImagen = this.firstChild.childNodes[i].attributes.id; 
            holder_mc._x = 45; 
            holder_mc._y = 194; 
            holder_mc.onRollOver  =  function(){          
               this._xscale =190; 
            this._yscale= 190; 
                                       }; 
                                        
            holder_mc.onRollOut  =  function(){          
               this._xscale =100; 
            this._yscale= 100; 
                                       }; 
            holder_mc.onPress  =  function(){ 
                
               gotoAndPlay(2);               }; 
             
                  } 
         //imagen del telefono 
         if (con==2){ 
            idImagen = this.firstChild.childNodes[i].attributes.id; 
            holder_mc._x = 80; 
            holder_mc._y = 270; 
             
             
                  } 
         // imagen usuario          
            if (con==3){ 
            idImagen = this.firstChild.childNodes[i].attributes.id; 
            holder_mc._x = 178; 
            holder_mc._y = 207; 
            holder_mc.onRollOver  =  function(){          
               this._xscale =190; 
            this._yscale= 190; 
             
            }; 
            holder_mc.onRollOut  =  function(){          
               this._xscale =100; 
            this._yscale= 100; 
             
            }; 
            holder_mc.onPress  =  function(){    
               gotoAndPlay(3);                
                                    }; 
                     } 
            //imagenTelefono          
            if (con==4){ 
            idImagen = this.firstChild.childNodes[i].attributes.id; 
            holder_mc._x = 205; 
            holder_mc._y = 280; 
                     } 
            //imagenUsuario          
            if (con==5){ 
            idImagen = this.firstChild.childNodes[i].attributes.id; 
            holder_mc._x = 275; 
            holder_mc._y = 181;    
            holder_mc.onRollOver  =  function(){          
               this._xscale =190; 
            this._yscale= 190; 
                                       }; 
            holder_mc.onRollOut  =  function(){          
               this._xscale =100; 
            this._yscale= 100; 
                                       }; 
            holder_mc.onPress  =  function(){       
             
               gotoAndPlay(4);               }; 
                
                     } 
               //imagenTelefono 
            if (con==6){ 
            idImagen = this.firstChild.childNodes[i].attributes.id; 
            holder_mc._x = 315; 
            holder_mc._y = 160;} 
            //imagenUsuario 
            if (con==7){ 
            idImagen = this.firstChild.childNodes[i].attributes.id; 
            holder_mc._x = 275; 
            holder_mc._y = 260; 
            holder_mc.onRollOver  =  function(){          
               this._xscale =190; 
            this._yscale= 190; 
                                       }; 
            holder_mc.onRollOut  =  function(){          
               this._xscale =100; 
            this._yscale= 100; 
                                    }; 
            holder_mc.onPress  =  function(){          
               gotoAndPlay(5);               }; 
                     } 
         //imagenTelefono 
         if (con==8){ 
            idImagen = this.firstChild.childNodes[i].attributes.id; 
            holder_mc._x = 315; 
            holder_mc._y = 335;} 
         if (con==9){ 
            idImagen = this.firstChild.childNodes[i].attributes.id; 
            holder_mc._x = 424; 
            holder_mc._y = 194; 
            holder_mc.onRollOver  =  function(){          
               this._xscale =190; 
            this._yscale= 190; 
                                       }; 
            holder_mc.onRollOut  =  function(){          
               this._xscale =100; 
            this._yscale= 100; 
                                    }; 
            holder_mc.onPress  =  function(){          
               gotoAndPlay(6);               }; 
 
            }          
                   
         if (con==10){ 
            idImagen = this.firstChild.childNodes[i].attributes.id; 
            holder_mc._x = 460; 
            holder_mc._y = 270; 
            }                   
         item.loadMovie(idImagen); 
         } 
   } 
}; 


y en los demas frames lo llamas con:

Código ActionScript :

miXML.load("http://10.6.2.113/SegHigiene/xml_fotos_estatus_SH.php"); 


igualmente la diferencia de peso va a ser nula, porque el texto no pesa nada. pero estaria mejor que lo hagas de esta forma porque si despues tenes que cambiar algo en el codigo solo lo vas a ser en uno y no vas a perder tiempo. he notado que aparenta ser algun tipo de libreria, entonces imagino que tenes un menu con botones que en la accion del boton se llama a un X fotograma y este tiene una galeria, seria pereferible que solo hagas una sola galeria y que cuando se precione en el boton, solo se llame al:

Código ActionScript :

miXML.load("http://10.6.2.113/SegHigiene/xml_fotos_estatus_SH.php"); 


de esta forma reducirias el peso.

Byee Saludos!

byee saludos!

Por wawi

325 de clabLevel

2 tutoriales

 

Argentina

firefox
Citar            
MensajeEscrito el 05 Sep 2009 12:39 am
ok lo hare asi de echo hasta el mismo xml es el ke se karga en todos los frames, nada mas que nunca e usado AS y no conosco muchos funcionalidades de As por eso son medios tontas mis preguntas:S

pero gracias

Por carych

37 de clabLevel



 

firefox

 

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