Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/03/2013, 05:35
marcwolf
 
Fecha de Ingreso: junio-2010
Mensajes: 353
Antigüedad: 13 años, 10 meses
Puntos: 6
Meter botones dinamicos por codigo en movieClip

Hola,

quiero meter botones creados dinamicamente en un movie clip que he puesto en el escenario

tengo este código que he modificado de este manual http://www.cristalab.com/tutoriales/...t-2.0-c48192l/
Código AS2:
Ver original
  1. //creamos un MovieClip vacio q funcionara como contenedor a nuestros botones
  2. //this.createEmptyMovieClip("botonera",this.getNextHighestDepth());
  3.  
  4. //creamos un Array con los nombres de los botones y q nos dira cuantos queremos
  5. var labels:Array = nom;
  6.  
  7. //usamos with() para escribir dentro del clip vacio
  8. with(botonera){
  9.    
  10.     //posicionamos la botonera
  11.     //this._x = 0;
  12.    
  13.     //creamos un for seteado por la longitud del Array
  14.     for(i=0;i < labels.length; i++){
  15.        
  16.         //declaramos una vaiable de tipo MovieClip q funcionara de modelo a nuestros botones
  17.         //le damos por valor cada boton attachado
  18.         var modelButton:MovieClip = _root.attachMovie("boton", "boton"+ i, _root.getNextHighestDepth());
  19.         //posicionamos los botones
  20.         modelButton._x = 0;
  21.         modelButton._y = ((i+1*0) + this._height) + 5; //multiplicamos por 0, para q la distancia sea constante
  22.        
  23.         //le ponemos titulo a cada boton, dados por los elementos del Array
  24.         modelButton.t.text = labels[i];
  25.        
  26.         //simulamos eventos RollOver y RollOut
  27.         modelButton.onEnterFrame = function (){
  28.            
  29.             //ecuacion para la trancicion de alpha
  30.             //donde: a = transparencia
  31.             //       v = velocidad de trancicion
  32.             this._alpha += (this.a - this._alpha) /this.v;
  33.                        
  34.             //si el cursor esta sobre el boton...          
  35.             if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
  36.                 //...cambia su transparencia al 50%
  37.                 this.a = 50;
  38.                 this.v = 5;
  39.                
  40.                 //sino, vuelve o se mantiene al 100%
  41.                 } else{
  42.                     this.a = 100;
  43.                     this.v = 10;
  44.                     }
  45.                 }
  46.         //simulamos eventos onRelease      
  47.         modelButton.onMouseDown = function (){
  48.             if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
  49.                 if(this._name == "boton1"){
  50.                     trace("welcome home")//acciones
  51.                 }
  52.                 if(this._name == "boton2"){
  53.                     trace("about us")//acciones
  54.                 }
  55.                 if(this._name == "boton3"){
  56.                     trace("our services")//acciones
  57.                 }
  58.                 if(this._name == "boton4"){
  59.                     trace("contact us")//acciones
  60.                 }
  61.             }
  62.         }
  63.     }
  64.        
  65. }

La cuestión es;

1) que si pongo _root.attachMovie("boton", "boton"+ i, _root.getNextHighestDepth()); mete los botones dinámicamente abajo del todo de la pelicula.. y da igual las modelButton._x o _y que le de que me lo pone en la misma coordenada..

2)También probé: botonera.attachMovie("boton", "boton"+ i, botonera.getNextHighestDepth()); y no aparece nada

3)También probé haciéndolo igual que en el manual pero cambiando la array y lo mismo me lo crea abajo del todo :S

4)No entiendo que eso de la profundida y no he encontrado información clara al respecto.

gracias de antemano