Comunidad de diseño web y desarrollo en internet online

clases dinamica creacion de botones con FOR en package

Citar            
MensajeEscrito el 23 Dic 2011 04:49 pm
Consegui hacer este codigo despues de uchos intentos

Código :

package clases
{
import flash.utils.*;
import flash.text.*;
import flash.events.*;
import flash.display.Sprite;
import flash.net.*;
import flash.display.*;
public dynamic class bot extends Sprite   {
public dynamic function bot(){
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*22;
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=260+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['tf'+n].borderColor=0xa5a5a5;
this['tf'+n].name='tf'+n;
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.CLICK,pulsado);
this['spr'+n].name='t'+n;spr02.addChild(this['spr'+n]);}
var ftt:TextFormat=new TextFormat();
var tfc:TextField=new TextField();
ftt.align='center';
ftt.size=20;
ftt.font='courier new';
tfc.defaultTextFormat=ftt;
tfc.text='horse';
tfc.x=215;
tfc.y=200;
tfc.selectable=false;
tfc.border=true;
tfc.width=370;
tfc.height=25;
spr02.addChild(tfc);
addChild(spr02);}
public function over(evt:MouseEvent){this['tf'+evt.target.name.substr(1)].backgroundColor=0xf1f1f1;};
public function out(evt:MouseEvent){this['tf'+evt.target.name.substr(1)].backgroundColor=0xffffff;};
public function pulsado(evt:MouseEvent){navigateToURL(new URLRequest("http://www.google.es"));};
}}

el archivo este se llama bot.as que se encuentra en un directorio "clases" como indica el package, luego el fla con el siguiente codigo

Código :

import clases.*;
var a:bot=new bot();
addChild(a);

todo correcto y me funciona a la perfeccion, ahora la pregunta del millon como puedo hacer para que cada haya una direccion diferente para cada click de boton, supongo que debo crear un array de direcciones que podria ser

Código :

var st02:Array=new Array ('http://www.google.es','http://www.yahoo.es','http://www.wikipedia.es','.......');
como debo asignar una funcion dinamica tendre que poner en vez de

Código :

public function pulsado(evt:MouseEvent){navigateToURL(new URLRequest("http://www.google.es"));};
poner

Código :

public dinamic function pulsado{....}
de antemano gracias por leerme

Por aukun

Claber

200 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 23 Dic 2011 04:52 pm
Como lo podria hacer para que cada boton me llevase a una direccion diferente teniendo en cuenta el array st02 que habia pensado para esa ocasion

Por aukun

Claber

200 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 23 Dic 2011 07:17 pm
El event.target del evento apunta a quien lo generó, puedes guardar en cada botón la URL destino si es un MovieClip, o ir dependiendo del nombre del boton

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 24 Dic 2011 04:00 am
hice lo que dijiste bueno eso creo, y con exito, y este es el resultado, perfecto e increible

Código :

package clases
{
import flash.utils.*;
import flash.text.*;
import flash.events.*;
import flash.display.Sprite;
import flash.net.*;
import flash.display.*;
public dynamic class bot extends Sprite   {
private var k3:uint;
private var st02:Array=new Array('http://www.google.es/','http://www.google.es/imghp?hl=es&tab=wi','http://www.google.es/videohp?hl=es','http://maps.google.es/maps?hl=es&tab=vl','','','','','','','','','','','','','','','','','','','','','','','','','','');
public dynamic function bot(){
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*22;
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=260+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['tf'+n].borderColor=0xa5a5a5;
this['tf'+n].name='tf'+n;
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.CLICK,pulsado);
this['spr'+n].name='t'+n;spr02.addChild(this['spr'+n]);}
var ftt:TextFormat=new TextFormat();
var tfc:TextField=new TextField();
ftt.align='center';
ftt.size=20;
ftt.font='courier new';
tfc.defaultTextFormat=ftt;
tfc.text='horse';
tfc.x=215;
tfc.y=200;
tfc.selectable=false;
tfc.border=true;
tfc.width=370;
tfc.height=25;
spr02.addChild(tfc);
addChild(spr02);}
public function over(evt:MouseEvent){this['tf'+evt.target.name.substr(1)].backgroundColor=0xf1f1f1;};
public function out(evt:MouseEvent){this['tf'+evt.target.name.substr(1)].backgroundColor=0xffffff;};
public function pulsado(evt:MouseEvent){
k3=(evt.target.name.substr(1));
navigateToURL(new URLRequest(st02[k3]));};
}}

simplemente increible gracias

Por aukun

Claber

200 de clabLevel



Genero:Masculino  

firefox

 

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