Comunidad de diseño web y desarrollo en internet online

Como hacer funciones dinamicas ???

Citar            
MensajeEscrito el 21 Oct 2011 03:08 pm
var r01:uint;var r02:uint;var k1:uint;var k2:uint;var spr02:Sprite=new Sprite;var n:uint;
var st01:Array=new Array('yuxtaposició','pрпак','teclat','colom','arreboire',
'contingut','blau','rentadora','cadira','ratoli','jerro','id¶☺a','pare','teclat',
'malson','desgracia','finestra','taronja','caball','lampada','escacs','tintorera',
'ura','plati','esquema','llantia','mag','electro','cantar','rodona');
var formatoTexto:TextFormat=new TextFormat();
for(n=0;n<=29;n++){
if((n>=0)&&(n<=9)){r01=n;r02=0;}if((n>=10)&&(n<=19)){r01=(n-10);r02=1;}if((n>=20)&&(n<=29)){r01=(n-20);r02=2;}
k1=r01*20;k2=r02*266;this['spr'+n]=new Sprite;this['tf'+n]=new TextField();
formatoTexto.color=0x000000;formatoTexto.size=11;formatoTexto.align='center';
formatoTexto.font='courier new';formatoTexto.bold=false;
this['tf'+n].defaultTextFormat=formatoTexto;
this['tf'+n].textColor = 0x000000;
this['tf'+n].x=25+k2;
this['tf'+n].y=160+k1;
this['tf'+n].border=true;
this['tf'+n].text = st01[n];
this['tf'+n].width=220;
this['tf'+n].height=20;
this['tf'+n].backgroundColor=0xff22ff;
this['spr'+n].addChild(this['tf'+n]);
this['spr'+n].buttonMode=true;
this['spr'+n].mouseChildren=false;
spr02.addChild(this['spr'+n]);
}
for(var m:uint=0;m<=29;m++){
this['tf'+m]=new TextField();
this['spr'+m]=new Sprite;
this['fout'+m]=new function();
this['fove'+m]=new function();
this['spr'+m].addEventListener(MouseEvent.ROLL_OUT,(this['fout'+m]));
this['spr'+m].addEventListener(MouseEvent.ROLL_OVER,(this['fove'+m]));
}
function fout1(e:MouseEvent):void{this['tf'+m].textColor=0xff0000;}
function fove1(e:MouseEvent):void{this['tf'+m].textColor=0x0000ff;}

addChild(spr02);

Por aukun

Claber

200 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 21 Oct 2011 03:25 pm
a ver me quedaria algo asi-->

Código ActionScript :

var r01:uint;var r02:uint;var k1:uint;var k2:uint;var spr02:Sprite=new Sprite;var n:uint;
var st01:Array=new Array('yuxtaposició','pрпак','teclat','colom','arreboire',
'contingut','blau','rentadora','cadira','ratoli','jerro','id¶☺a','pare','teclat',
'malson','desgracia','finestra','taronja','caball','lampada','escacs','tintorera',
'ura','plati','esquema','llantia','mag','electro','cantar','rodona');
var formatoTexto:TextFormat=new TextFormat();
for(n=0;n<=29;n++){            
   if((n>=0)&&(n<=9)){r01=n;r02=0;}if((n>=10)&&(n<=19)){r01=(n-10);r02=1;}if((n>=20)&&(n<=29)){r01=(n-20);r02=2;}
    k1=r01*20;k2=r02*266;this['spr'+n]=new Sprite;this['tf'+n]=new TextField();
    formatoTexto.color=0x000000;formatoTexto.size=11;formatoTexto.align='center';
   formatoTexto.font='courier new';formatoTexto.bold=false; 
    this['tf'+n].defaultTextFormat=formatoTexto; 
    this['tf'+n].textColor = 0x000000; 
    this['tf'+n].x=25+k2; 
    this['tf'+n].y=160+k1; 
    this['tf'+n].border=true; 
    this['tf'+n].text = st01[n]; 
    this['tf'+n].width=220; 
    this['tf'+n].height=20;
   this['tf'+n].backgroundColor=0xff22ff;
    this['spr'+n].addChild(this['tf'+n]); 
    this['spr'+n].buttonMode=true; 
   this['spr'+n].mouseChildren=false;    
   this['spr'+n].addEventListener(MouseEvent.ROLL_OUT,this['fout'+n]);
    this['spr'+n].addEventListener(MouseEvent.ROLL_OVER,this['fove'+n]);
   
    spr02.addChild(this['spr'+n]);    
       } 
function fout0(e:MouseEvent):void{this.tf0.textColor=0xff0000;}
function fove0(e:MouseEvent):void{this.tf0.textColor=0x0000ff;}       
function fout1(e:MouseEvent):void{this.tf1.textColor=0xff0000;}
function fove1(e:MouseEvent):void{this.tf1.textColor=0x0000ff;}       
function fout2(e:MouseEvent):void{this.tf2.textColor=0xff0000;}
function fove2(e:MouseEvent):void{this.tf2.textColor=0x0000ff;}       
function fout3(e:MouseEvent):void{this.tf3.textColor=0xff0000;}
function fove3(e:MouseEvent):void{this.tf3.textColor=0x0000ff;}       
function fout4(e:MouseEvent):void{this.tf4.textColor=0xff0000;}
function fove4(e:MouseEvent):void{this.tf4.textColor=0x0000ff;}       
function fout5(e:MouseEvent):void{this.tf5.textColor=0xff0000;}
function fove5(e:MouseEvent):void{this.tf5.textColor=0x0000ff;}       
function fout6(e:MouseEvent):void{this.tf6.textColor=0xff0000;}
function fove6(e:MouseEvent):void{this.tf6.textColor=0x0000ff;}       
function fout7(e:MouseEvent):void{this.tf7.textColor=0xff0000;}
function fove7(e:MouseEvent):void{this.tf7.textColor=0x0000ff;}       
function fout8(e:MouseEvent):void{this.tf8.textColor=0xff0000;}
function fove8(e:MouseEvent):void{this.tf8.textColor=0x0000ff;}       
function fout9(e:MouseEvent):void{this.tf9.textColor=0xff0000;}
function fove9(e:MouseEvent):void{this.tf9.textColor=0x0000ff;}       
function fout10(e:MouseEvent):void{this.tf10.textColor=0xff0000;}
function fove10(e:MouseEvent):void{this.tf10.textColor=0x0000ff;}       
function fout11(e:MouseEvent):void{this.tf11.textColor=0xff0000;}
function fove11(e:MouseEvent):void{this.tf11.textColor=0x0000ff;}       
function fout12(e:MouseEvent):void{this.tf12.textColor=0xff0000;}
function fove12(e:MouseEvent):void{this.tf12.textColor=0x0000ff;}       
function fout13(e:MouseEvent):void{this.tf13.textColor=0xff0000;}
function fove13(e:MouseEvent):void{this.tf13.textColor=0x0000ff;}       
function fout14(e:MouseEvent):void{this.tf14.textColor=0xff0000;}
function fove14(e:MouseEvent):void{this.tf14.textColor=0x0000ff;}       
function fout15(e:MouseEvent):void{this.tf15.textColor=0xff0000;}
function fove15(e:MouseEvent):void{this.tf15.textColor=0x0000ff;}   
function fout16(e:MouseEvent):void{this.tf16.textColor=0xff0000;}
function fove16(e:MouseEvent):void{this.tf16.textColor=0x0000ff;}       
function fout17(e:MouseEvent):void{this.tf17.textColor=0xff0000;}
function fove17(e:MouseEvent):void{this.tf17.textColor=0x0000ff;}       
function fout18(e:MouseEvent):void{this.tf18.textColor=0xff0000;}
function fove18(e:MouseEvent):void{this.tf18.textColor=0x0000ff;}       
function fout19(e:MouseEvent):void{this.tf19.textColor=0xff0000;}
function fove19(e:MouseEvent):void{this.tf19.textColor=0x0000ff;}       
function fout20(e:MouseEvent):void{this.tf20.textColor=0xff0000;}
function fove20(e:MouseEvent):void{this.tf20.textColor=0x0000ff;}       
function fout21(e:MouseEvent):void{this.tf21.textColor=0xff0000;}
function fove21(e:MouseEvent):void{this.tf21.textColor=0x0000ff;}       
function fout22(e:MouseEvent):void{this.tf22.textColor=0xff0000;}
function fove22(e:MouseEvent):void{this.tf22.textColor=0x0000ff;}       
function fout23(e:MouseEvent):void{this.tf23.textColor=0xff0000;}
function fove23(e:MouseEvent):void{this.tf23.textColor=0x0000ff;}       
function fout24(e:MouseEvent):void{this.tf24.textColor=0xff0000;}
function fove24(e:MouseEvent):void{this.tf24.textColor=0x0000ff;}       
function fout25(e:MouseEvent):void{this.tf25.textColor=0xff0000;}
function fove25(e:MouseEvent):void{this.tf25.textColor=0x0000ff;}   
function fout26(e:MouseEvent):void{this.tf26.textColor=0xff0000;}
function fove26(e:MouseEvent):void{this.tf26.textColor=0x0000ff;}       
function fout27(e:MouseEvent):void{this.tf27.textColor=0xff0000;}
function fove27(e:MouseEvent):void{this.tf27.textColor=0x0000ff;}       
function fout28(e:MouseEvent):void{this.tf28.textColor=0xff0000;}
function fove28(e:MouseEvent):void{this.tf28.textColor=0x0000ff;}       
function fout29(e:MouseEvent):void{this.tf29.textColor=0xff0000;}
function fove29(e:MouseEvent):void{this.tf29.textColor=0x0000ff;}
addChild(spr02);

como hacer que la assignacion de funciones sean dinamicas para hacer que el codigo sea lo menos pesado posible.????

Por aukun

Claber

200 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 21 Oct 2011 09:29 pm
La idea es que hagas una sola función que reciba los rollOut y rollOver y uses evt.target, que apunta a quien emitió el evento para cambiar el color. Por ejemplo con dos funciones pasas a rojo o amarillo

Código ActionScript :

function over(evt:MouseEvent):void{
   TextField(evt.target).textColor = 0xff0000
}
function out(evt:MouseEvent):void{
   TextField(evt.target).textColor = 0x0000ff
}


Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 22 Oct 2011 04:32 am
no funciona soliarg, eso ya lo intente pero no funca me aparecen errores del tipo error 1034:Error de conversion forzada:no se puede convertir flash.display::Sprite@3c57b681 en flash.text.TextField, creeme eso ya hace tiempo que lo intente

Por aukun

Claber

200 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 22 Oct 2011 11:45 am
¿A que cosa le estás poniendo el listener?

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 22 Oct 2011 09:07 pm
perdona por contestar tarde soliarg, y gracias de antemano por la ayuda, bien yo le pongo el listener dentro del for y pongo

Código ActionScript :

this['spr'+n].addEventListener(MouseEvent.ROLL_OUT,this['fout'+n]); 
    this['spr'+n].addEventListener(MouseEvent.ROLL_OVER,this['fove'+n]); 

en el sprite que le corresponde, es que ahora que lo dices no entiendo demasiado lo del target pero me da conversion forzada en la consola output se que estoy haciendo algo mal pero no se que es te doy todo el codigo

Código ActionScript :

var r01:uint;var r02:uint;var k1:uint;var k2:uint;var spr02:Sprite=new Sprite;var n:uint; 
var st01:Array=new Array('yuxtaposició','pрпак','teclat','colom','arreboire', 
'contingut','blau','rentadora','cadira','ratoli','jerro','id¶☺a','pare','teclat', 
'malson','desgracia','finestra','taronja','caball','lampada','escacs','tintorera', 
'ura','plati','esquema','llantia','mag','electro','cantar','rodona'); 
var formatoTexto:TextFormat=new TextFormat(); 
for(n=0;n<=29;n++){             
   if((n>=0)&&(n<=9)){r01=n;r02=0;}if((n>=10)&&(n<=19)){r01=(n-10);r02=1;}if((n>=20)&&(n<=29)){r01=(n-20);r02=2;} 
    k1=r01*20;k2=r02*266;this['spr'+n]=new Sprite;this['tf'+n]=new TextField(); 
    formatoTexto.color=0x000000;formatoTexto.size=11;formatoTexto.align='center'; 
   formatoTexto.font='courier new';formatoTexto.bold=false;  
    this['tf'+n].defaultTextFormat=formatoTexto;  
    this['tf'+n].textColor = 0x000000;  
    this['tf'+n].x=25+k2;  
    this['tf'+n].y=160+k1;  
    this['tf'+n].border=true;  
    this['tf'+n].text = st01[n];  
    this['tf'+n].width=220;  
    this['tf'+n].height=20; 
   this['tf'+n].backgroundColor=0xff22ff; 
    this['spr'+n].addChild(this['tf'+n]);  
    this['spr'+n].buttonMode=true;  
   this['spr'+n].mouseChildren=false;     
   this['spr'+n].addEventListener(MouseEvent.ROLL_OUT,out); 
   this['spr'+n].addEventListener(MouseEvent.ROLL_OVER,over);
   spr02.addChild(this['spr'+n]);     
       }  
function over(evt:MouseEvent):void{ 
   TextField(evt.target).textColor = 0xffff00 
} 
function out(evt:MouseEvent):void{ 
   TextField(evt.target).textColor = 0x00ffff 
}

addChild(spr02);

Por aukun

Claber

200 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 22 Oct 2011 09:35 pm
Ok, si le agregas el listener al sprite, pero el cambio se lo haces a una caja de texto, entonces no puedes usar el target. Tiene que haber alguna relación entre el Sprite y la caja de texto, por ejemplo si el nombre de instancia del sprite empieza con S y el de la caja de texto con T, se podría hacer algo asi:

[as]
function over(evt:MouseEvent):void{
var nombre:String = evt.target.name.substr(1);
TextField(this["T"+nombre]).textColor = 0xff0000
}
function out(evt:MouseEvent):void{
var nombre:String = evt.target.name.substr(1);
TextField(this["T"+nombre]).textColor = 0x0000ff
}[as]

Si no hay un tipo de relación de ese estilo entre el TextField y el Sprite, entonces dejalo como lo tienes

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 23 Oct 2011 06:58 am
creo que me has dado una idea soliarg en vez de substr(1), solo tengo que poner substr(8), he estado probando y ahora entiendo mejor lo del comando target voy a hacer unos experimentos mas, creo que lo podre conseguir te envio el codigo que me haya quedado luego.

Por aukun

Claber

200 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 23 Oct 2011 07:14 am
OLEEEEE, he hecho la siguiente prueba no entiendo muy bien porque me multiplica por dos los nombres de las instancias pero creo que podre hacer un arreglo te envio la prueba

Código ActionScript :

var r01:uint;var r02:uint;var k1:uint;var k2:uint;var spr02:Sprite=new Sprite;var n:uint; 
var st01:Array=new Array('yuxtaposició','pрпак','teclat','colom','arreboire', 
'contingut','blau','rentadora','cadira','ratoli','jerro','id¶☺a','pare','teclat', 
'malson','desgracia','finestra','taronja','caball','lampada','escacs','tintorera', 
'ura','plati','esquema','llantia','mag','electro','cantar','rodona'); 
var formatoTexto:TextFormat=new TextFormat(); 
for(n=0;n<=29;n++){             
   if((n>=0)&&(n<=9)){r01=n;r02=0;}if((n>=10)&&(n<=19)){r01=(n-10);r02=1;}if((n>=20)&&(n<=29)){r01=(n-20);r02=2;} 
    k1=r01*20;k2=r02*266;this['spr'+n]=new Sprite;
   this['tf'+n]=new TextField(); 
    formatoTexto.color=0x000000;formatoTexto.size=11;formatoTexto.align='center'; 
   formatoTexto.font='courier new';formatoTexto.bold=false;  
    this['tf'+n].defaultTextFormat=formatoTexto;  
    this['tf'+n].textColor = 0x000000;  
    this['tf'+n].x=25+k2;  
    this['tf'+n].y=160+k1;  
    this['tf'+n].border=true;  
    this['tf'+n].text = st01[n];  
    this['tf'+n].width=220;  
    this['tf'+n].height=20; 
   this['tf'+n].backgroundColor=0xff22ff; 
    this['spr'+n].addChild(this['tf'+n]);  
    this['spr'+n].buttonMode=true;  
    this['spr'+n].mouseChildren=false;     
    this['spr'+n].addEventListener(MouseEvent.ROLL_OUT,out); 
    this['spr'+n].addEventListener(MouseEvent.ROLL_OVER,over); 
     
    spr02.addChild(this['spr'+n]);     
       }  
    function over(evt:MouseEvent):void{trace(evt.target.name.substr(8));};
    function out(evt:MouseEvent):void{trace(evt.target.name.substr(8));};   
addChild(spr02);

el resultado en el output es el siguiente
cuando pongo el mouse encima del primer boton el output me pone -->
2
cuando pongo el mouse encima del segundo boton el output me pone -->
2 -->porque el mouse salio del primer boton
4 -->porque el mouse entro en el segundo boton ..
cuando pongo el mouse encima del tercer boton el output me pone -->
4
6
Esto es fantastico.. a ver si lo consigo, gracias por la idea tenia que hacer unos experimentos es que no entendi bien lo del target t envio el codigo acabado

Por aukun

Claber

200 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 23 Oct 2011 07:28 am
Gracias nen eres un crack, joer por esa tonteria del target que no conocia las posibilidades ahora de lo que puedo llegar ha hacer con AS3 se me han ampliado exponencialmente solo he tenido que hacer lo siguiente:

Código ActionScript :

 function over(evt:MouseEvent):void{this['tf'+(((evt.target.name.substr(8))-2)/2)].textColor=0xff0000;};
    function out(evt:MouseEvent):void{this['tf'+(((evt.target.name.substr(8))-2)/2)].textColor=0x0000ff;};

la totalidad del codigo me quedo asi

Código ActionScript :

var r01:uint;var r02:uint;var k1:uint;var k2:uint;var spr02:Sprite=new Sprite;var n:uint; 
var st01:Array=new Array('yuxtaposició','pрпак','teclat','colom','arreboire', 
'contingut','blau','rentadora','cadira','ratoli','jerro','id¶☺a','pare','teclat', 
'malson','desgracia','finestra','taronja','caball','lampada','escacs','tintorera', 
'ura','plati','esquema','llantia','mag','electro','cantar','rodona'); 
var formatoTexto:TextFormat=new TextFormat(); 
for(n=0;n<=29;n++){             
   if((n>=0)&&(n<=9)){r01=n;r02=0;}if((n>=10)&&(n<=19)){r01=(n-10);r02=1;}if((n>=20)&&(n<=29)){r01=(n-20);r02=2;} 
    k1=r01*20;k2=r02*266;this['spr'+n]=new Sprite;
   this['tf'+n]=new TextField(); 
    formatoTexto.color=0x000000;formatoTexto.size=11;formatoTexto.align='center'; 
   formatoTexto.font='courier new';formatoTexto.bold=false;  
    this['tf'+n].defaultTextFormat=formatoTexto;  
    this['tf'+n].textColor = 0x000000;  
    this['tf'+n].x=25+k2;  
    this['tf'+n].y=160+k1;  
    this['tf'+n].border=true;  
    this['tf'+n].text = st01[n];  
    this['tf'+n].width=220;  
    this['tf'+n].height=20; 
   this['tf'+n].backgroundColor=0xff22ff; 
    this['spr'+n].addChild(this['tf'+n]);  
    this['spr'+n].buttonMode=true;  
    this['spr'+n].mouseChildren=false;     
    this['spr'+n].addEventListener(MouseEvent.ROLL_OUT,out); 
    this['spr'+n].addEventListener(MouseEvent.ROLL_OVER,over); 
    //this['spr'+n].addEventListener(MouseEvent.ROLL_OUT,this['fout'+n]); 
//    this['spr'+n].addEventListener(MouseEvent.ROLL_OVER,this['fove'+n]);
   
    spr02.addChild(this['spr'+n]);     
       }  
    function over(evt:MouseEvent):void{this['tf'+(((evt.target.name.substr(8))-2)/2)].textColor=0xff0000;};
    function out(evt:MouseEvent):void{this['tf'+(((evt.target.name.substr(8))-2)/2)].textColor=0x0000ff;};
addChild(spr02);

mil gracias nen

Por aukun

Claber

200 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 23 Oct 2011 07:41 am
IMPRESIONANTE redux del codigo

Código ActionScript :

var r01:uint;var r02:uint;var k1:uint;var k2:uint;var spr02:Sprite=new Sprite;var n:uint; 
var st01:Array=new Array('yuxtaposició','pрпак','teclat','colom','arreboire', 
'contingut','blau','rentadora','cadira','ratoli','jerro','id¶☺a','pare','teclat', 
'malson','desgracia','finestra','taronja','caball','lampada','escacs','tintorera', 
'ura','plati','esquema','llantia','mag','electro','cantar','rodona'); 
var formatoTexto:TextFormat=new TextFormat(); 
for(n=0;n<=29;n++){             
   if((n>=0)&&(n<=9)){r01=n;r02=0;}if((n>=10)&&(n<=19)){r01=(n-10);r02=1;}if((n>=20)&&(n<=29)){r01=(n-20);r02=2;} 
   k1=r01*20;k2=r02*266;this['spr'+n]=new Sprite;this['tf'+n]=new TextField(); 
   formatoTexto.color=0x000000;formatoTexto.size=11;formatoTexto.align='center'; 
   formatoTexto.font='courier new';formatoTexto.bold=false;this['tf'+n].defaultTextFormat=formatoTexto;  
   this['tf'+n].textColor = 0x000000;this['tf'+n].x=25+k2;this['tf'+n].y=160+k1;this['tf'+n].border=true;  
   this['tf'+n].text = st01[n];this['tf'+n].width=220;this['tf'+n].height=20;this['tf'+n].background=true;
   this['tf'+n].backgroundColor=0xffffff; 
   this['spr'+n].addChild(this['tf'+n]);this['spr'+n].buttonMode=true;this['spr'+n].mouseChildren=false;     
   this['spr'+n].addEventListener(MouseEvent.ROLL_OUT,out);this['spr'+n].addEventListener(MouseEvent.ROLL_OVER,over); 
   spr02.addChild(this['spr'+n]);}  ////-->final del for
function over(evt:MouseEvent):void{this['tf'+(((evt.target.name.substr(8))-2)/2)].backgroundColor=0xf1f1f1;};
function out(evt:MouseEvent):void{this['tf'+(((evt.target.name.substr(8))-2)/2)].backgroundColor=0xffffff;};
addChild(spr02);

Por aukun

Claber

200 de clabLevel



Genero:Masculino  

firefox

 

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