Comunidad de diseño web y desarrollo en internet online

problema con LOOPs y SimpleButton

Citar            
MensajeEscrito el 20 Jun 2011 07:45 pm
Hola a todos,
Estoy empezando con AS3, creo que nunca voy a dejar de empezar... jejeje :oops:
y tengo varios problemillas.
Tengo que hacer una barra de navegación, todita con código, con 5 botones y que al hacer click en cada boton se quede en downState y aparezca una imagen.

tengo problemas en varias cosas:
-dejar el boton en down state, no tengo ni idea de como se hace
- en borrar las imágenes, no se porqué no se me borran...

abajo os paso mi codigo a ver si me podeis echar una mano.
Muchas gracias

lui

Código ActionScript :

 
import flash.display.MovieClip;
import flash.filters.*; 

var myBevel:BevelFilter = new BevelFilter();
   myBevel.type = BitmapFilterType.INNER;
   myBevel.distance = 3;
   myBevel.highlightColor = 0xCFF8FF;
   myBevel.shadowColor = 0x333333;
   myBevel.blurX = 2;
   myBevel.blurY = 2;
   myBevel.shadowAlpha = .3;

var fuente1:Font = new HelveticaRegular();
var fuente2:Font = new HelveticaBold();

var textoBotones:Array = new Array("IMAGEN 1","IMAGEN 2","IMAGEN 3","IMAGEN 4","IMAGEN 5")
var btn:SimpleButton;


var container1:Sprite = new Sprite();
container1.x = 300;
container1.y = 150;

var dibujito1:Shape;
var dibujito2:Shape;
var dibujito3:Shape;
var dibujito4:Shape;
var dibujito5:Shape;

//-------- Loop para crear los botones-----------------
for (var i:uint = 0; i<5; i++){

var tf:TextFormat = new TextFormat();
   tf.color = 0x000000;
   tf.font = fuente1.fontName;
   tf.size = 15;
   tf.align = TextFormatAlign.CENTER;

var tf2:TextFormat = new TextFormat();
   tf2.color = 0x000000;
   tf2.font = fuente2.fontName;;
   tf2.size = 15;
   tf2.bold = true;
    tf2.align = TextFormatAlign.CENTER;
   
var txt:TextField = new TextField();
   txt.defaultTextFormat =tf;
   txt.text = textoBotones[i];
   txt.width = txt.textWidth+5;
   txt.height = txt.textHeight+5;

var txt2:TextField = new TextField();
   txt2.defaultTextFormat = tf2;
   txt2.text = textoBotones[i];
   txt2.width = txt2.textWidth+5;
   txt2.height = txt2.textHeight+5;

var txt3:TextField = new TextField();
   txt3.defaultTextFormat = tf2;
   txt3.text = textoBotones[i];
   txt3.width = txt3.textWidth+5;
   txt3.height = txt3.textHeight+5;
   
var estado1:Shape = new Shape;
   estado1.graphics.beginFill(0xFFFFFF);
   estado1.graphics.drawRect(0,0,120,30);
   estado1.graphics.endFill();

var estado2:Shape = new Shape;
   estado2.graphics.beginFill(0xFFFFFF);
   estado2.graphics.drawRect(0,0,120,30);
   estado2.graphics.endFill();
   
var estado3:Shape = new Shape;
   estado3.graphics.beginFill(0xDDDDDD);
   estado3.graphics.drawRect(0,0,120,30);
   estado3.graphics.endFill();   

var mcUp:MovieClip = new MovieClip();
   mcUp.addChild(estado1);
   mcUp.addChild(txt);


var mcOver:MovieClip = new MovieClip();
   mcOver.addChild(estado2);
   mcOver.addChild(txt2);
   
var mcDown:MovieClip = new MovieClip();
   mcDown.addChild(estado3);
   mcDown.addChild(txt3);
   mcDown.filters = [myBevel];

   
   txt.x = (estado1.width -txt.width)/2;
   txt.y = (estado1.height -txt.height)/2;
   
   txt2.x = (estado2.width -txt2.width)/2;
   txt2.y = (estado2.height -txt2.height)/2;
   
   txt3.x = (estado3.width -txt3.width)/2;
   txt3.y = (estado3.height -txt3.height)/2;
 
   btn = new SimpleButton();
   btn.upState = mcUp;
   btn.overState = mcOver;
   btn.downState = mcDown;
   btn.hitTestState = btn.upState;
   btn.trackAsMenu = true;
   btn.useHandCursor = true;
   btn.x = 50+btn.width*i;
   btn.y = stage.stageHeight - btn.height - 20;
   btn.name= "elboton"+i;
 
addChild( btn );
btn.addEventListener(MouseEvent.CLICK, botonActivo);

}

//--------Fin del loop para crear botones---------------
//------------------------------------------------------

//--------A ver si consigo que los botones hagan algo---------------

function botonActivo(evt:MouseEvent){
   trace(evt.currentTarget.name);

   if(evt.currentTarget.name =="elboton0"){
      borrarImagenes();
      addChild(container1);
      container1.addChild(dibujito1);
   } else 
      if(evt.currentTarget.name =="elboton1"){
      borrarImagenes();
      addChild(container1);
      container1.addChild(dibujito2);
   } else
      if(evt.currentTarget.name =="elboton2"){
      borrarImagenes();
      addChild(container1);
      container1.addChild(dibujito3);
   } else
      if(evt.currentTarget.name =="elboton3"){
      borrarImagenes();
      addChild(container1);
      container1.addChild(dibujito4);
   } else
      if(evt.currentTarget.name =="elboton4"){
      borrarImagenes();
      addChild(container1);
      container1.addChild(dibujito5);
   }   
}


function borrarImagenes(){
   removeChild(container1);
}


//------------------Dibujitos------------------------
// quito el codigo de losdibujitos, porque solo hace bulto, estan echos con new Shape

Por lui_cm

1 de clabLevel



 

firefox
Citar            
MensajeEscrito el 21 Jun 2011 02:05 pm
La verdad es que es demasiado código y me pierdo, pero un par de tips>

- Usa MovieClips con botones, en cada click haz que el resto vuelva al estado default (puedes tener referencias en un array para todos los botones) y luego mueve el seleccionado al estado down
- Si quieres mostrar una imagen externa, reutiliza siempre el mismo Loader, eso asegura que la imagen nueva reemplace la anterior

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox

 

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