lo intente pero no se puede
Código :
stop();
//funcion de alinear
function alignButtons(nombre:String, contenedor:MovieClip, begin:Number, distance:Number, excludeButton:MovieClip):Void {
var posY:Number = begin;
var botones:Array = new Array();
var numero:Number;
//---Guardar los movies en un arreglo
for (var obj in contenedor) {
if (contenedor[obj] instanceof MovieClip && contenedor[obj]._name.indexOf(nombre) >= 0) {
numero = Number(obj.slice(nombre.length, obj.length));
botones.push({nombre:obj, numero:numero});
}
}
//---Ordenar los movies
botones.sortOn("numero",Array.NUMERIC);
//---Posicionar los movies
for (var i:Number = 0; i < botones.length; i++) {
if (contenedor[botones[i].nombre] != excludeButton) {
contenedor[botones[i].nombre]._y = posY;
posY += contenedor[botones[i].nombre]._height + distance;
}
}
}
//termino la funcion
//todos los chiches para los botones
var boton:MovieClip;
var fondo:MovieClip;
var texto:TextField;
var estilo:TextFormat = new TextFormat();
var ancho:Number;
var alto:Number;
var posY:Number = 40;
var posX:Number = 700;
with(estilo){
font = "Arial";
size = 15;
color = 0x666666;
}
var valores:Array = new Array("articulo1", "articulo2", "articulo3",
"articulo4", "articulo5", "articulo6");
//---Arreglo que guarda los valores añadidos al carrito
var added:Array = new Array();
//terminaron los chiches xD
for(var i:Number = 0; i < valores.length; i++){
attachMovie("Accordion", "miAcordeon", 1);
miAcordeon.move(150, 200);
//Propiedades del componente
miAcordeon.setSize(100, 200);
// Cambiar el color del componente
miAcordeon.setStyle("themeColor", 0xCCFFFF);
miAcordeon.setStyle("backgroundColor", 0xCCFFFF);
miAcordeon.setStyle("borderColor", 0xCCFFFF);
miAcordeon.setStyle("borderStyle", "none");
miAcordeon.setStyle("headerHeight", 20);
miAcordeon.setStyle("fontFamily", "Arial");
miAcordeon.setStyle("fontSize", 10);
//Le ponemos las opciones del menú
miAcordeon.createChild("View", "opcion1", {label:"MARCA 1"});
miAcordeon.createChild("View", "opcion2", {label:"MARCA 2"});
miAcordeon.createChild("View", "opcion3", {label:"MARCA 3"});
miAcordeon.createChild("View", "opcion4", {label:"MARCA 4"});
miAcordeon.createChild("View", "opcion5", {label:"MARCA 5"});
miAcordeon.createChild("View", "opcion6", {label:"MARCA 6"});
miAcordeon.createChild("View", "opcion7", {label:"MARCA 7"});
//Propiedades de los objetos vinculados
miAcordeon.opcion1.createChild("boton1", "boton1_mc");
miAcordeon.opcion1.boton1_mc.move(50, 10);
miAcordeon.opcion1.boton1_mc.onRelease=function(){
_root.attachMovie("prueba", "imagen1", 2);
_root.attachMovie("agregar", "articulo0", 3);
_root.imagen1._x=260;
_root.imagen1._y=200;
_root.articulo0._x=590;
_root.articulo0._y=415;
}
miAcordeon.opcion1.createChild("boton2", "boton2_mc");
miAcordeon.opcion1.boton2_mc.move(50, 40);
miAcordeon.opcion1.boton2_mc.onRelease=function(){
_root.attachMovie("prueba", "imagen2", 2);
_root.attachMovie("agregar", "articulo1", 3);
_root.imagen2._x=260;
_root.imagen2._y=200;
_root.articulo1._x=590;
_root.articulo1._y=415;
}
miAcordeon.opcion2.createChild("boton3", "boton3_mc");
miAcordeon.opcion2.boton3_mc.move(50, 10);
miAcordeon.opcion2.boton3_mc.onRelease=function(){
_root.attachMovie("prueba", "imagen3", 2);
_root.attachMovie("agregar", "articulo2", 3);
_root.imagen3._x=260;
_root.imagen3._y=200;
_root.articulo2._x=590;
_root.articulo2._y=415;
}
miAcordeon.opcion2.createChild("boton4", "boton4_mc");
miAcordeon.opcion2.boton4_mc.move(50, 40);
miAcordeon.opcion2.boton4_mc.onRelease=function(){
_root.attachMovie("prueba", "imagen4", 2);
_root.attachMovie("agregar", "articulo3", 3);
_root.imagen4._x=260;
_root.imagen4._y=200;
_root.articulo3._x=590;
_root.articulo3._y=415;
}
miAcordeon.opcion3.createChild("boton5", "boton5_mc");
miAcordeon.opcion3.boton5_mc.move(50, 10);
miAcordeon.opcion3.boton5_mc.onRelease=function(){
_root.attachMovie("prueba", "imagen5", 2);
_root.attachMovie("agregar", "articulo4", 3);
_root.imagen5._x=260;
_root.imagen5._y=200;
_root.articulo4._x=590;
_root.articulo4._y=415;
}
miAcordeon.opcion3.createChild("boton6", "boton6_mc");
miAcordeon.opcion3.boton6_mc.move(50, 40);
miAcordeon.opcion3.boton6_mc.onRelease=function(){
_root.attachMovie("prueba", "imagen6", 2);
_root.attachMovie("agregar", "articulo5", 3);
_root.imagen6._x=260;
_root.imagen6._y=200;
_root.articulo5._x=590;
_root.articulo5._y=415;
}
this["articulo" + i].numero = i;
this["articulo" + i].onRelease = function():Void{
this.gotoAndStop(3);
added.addToArray(valores[this.numero]);
boton = this._parent.createEmptyMovieClip("boton" +[this.numero], this._parent.getNextHighestDepth());
alignButtons("boton", _root, 0, 15, this);
boton.item =valores[this.numero];
fondo = boton.createEmptyMovieClip("fondo", boton.getNextHighestDepth());
texto = boton.createTextField("texto", boton.getNextHighestDepth(), 0, 0, 0, 0);
with(texto){
autoSize = true;
selectable = false;
text = valores[this.numero];
setTextFormat(estilo);
}
ancho = texto._width;
alto = texto._height;
with(fondo){
beginFill(0x000000, 10);
moveTo(-2, -2);
lineTo(ancho + 4, -2);
lineTo(ancho + 4, alto + 4);
lineTo(0, alto + 4);
lineTo(0, 0);
endFill();
}
//---Situar los botones
boton._x = posX;
boton.onRollOver = function():Void{
this.texto.textColor = "0xCCFFFF";
}
boton.onRollOut = function():Void{
setTextFormat(estilo);
}
boton.onPress = function():Void{
this.texto.textColor = "0x99FFFF";
}
boton.onRelease = function():Void{
added.deleteToArray(this.item);
alignButtons("boton", _root, 40, 15, this);
this.removeMovieClip();
this.texto.textColor = "0x666666";
}
boton.onReleaseOutside = function():Void{
this.texto.textColor = "0x666666";
}
alignButtons("boton", _root, 0, 15, null);
trace(added);
}
}
//---Prototype de añadir
Array.prototype.addToArray = function(valor):Void{
if(this.indexOf(valor) < 0){
this.push(valor);
}
}
//---Prototype de eliminar
Array.prototype.deleteToArray = function(valor):Void{
var index:Number = this.indexOf(valor);
if(index >= 0){
this.splice(index, 1);
}
}
//---Prototype de indexOf
Array.prototype.indexOf = function(search):Number{
var total:Number = this.length;
var index:Number = -1;
var item:Number = 0;
var finded:Boolean = false;
while(item < total && !finded){
if(this[item] == search){
index = item;
finded = true;
}else{
item++;
}
}
return index;
}