Comunidad de diseño web y desarrollo en internet online

crear una función dinámicamente

Citar            
MensajeEscrito el 03 Jul 2009 02:52 pm
hola,
les hago una consulta.
¿es posible crear una función dinámicamente?
por ej, se puede hacer en nombre de un movie o variable dinámicamente con los corchetes
this["item"+i] = ....

pero si quiero hacer lo mismo con una función no me funciona
function this["item"+i](){
}

estuve dándole vueltas y no doy en el clavo, si alguien sabe la respuesta me vendría muy bien.

Desde ya gracias
saludos

Por stereo-tipo

10 de clabLevel



 

msie7
Citar            
MensajeEscrito el 03 Jul 2009 04:34 pm
¿?¿?¿? ¿Para qué quieres hacer eso?

Por juanfher

74 de clabLevel



 

firefox
Citar            
MensajeEscrito el 03 Jul 2009 08:06 pm
Hola again
Quiero que en una función se dupliquen varios MC con propiedades todo dependiendo de un xml.
Después se pasa de uno a otro con una flecha. Para esto tiene que ser dinámica la función asi se duplica dependiendo de la cantidad de datos que se llenaron en el xml.

pego el codigo que hice, es medio largo, lo que tendrias que ver es desde function scroll_1() para abajo. Todo eso tendria que duplicarse dinamicamente. dependiendo de la variable total_scroll

saludos


///////////////////////////////////////////////////////////////////////////////////////// Array + XML
numero_items = new Array();
Thumb_img = new Array();
//img_grande = new Array();
eleccion_uno = new Array();
eleccion_dos = new Array();
eleccion_tres = new Array();
eleccion_cuatro = new Array();
eleccion_cinco = new Array();

img_recuadro = this.items_xml.childNodes[1].childNodes // img grande ref
this.img_ref.img.drop.loadMovie(img_recuadro)
trace("imagen recuadro: "+img_recuadro)

this.fraseMovie.fraseaTraducir = this.items_xml.childNodes[2].childNodes[0].childNodes // la frase a traducir
trace("frase a traducir: "+this.fraseMovie.fraseaTraducir)

each_scroll = items_xml.childNodes[0].childNodes;
each_scroll = _global.total_scroll=each_scroll.length;
trace ("total_scroll: "+total_scroll)

ie = 0
while (ie < total_scroll) {
this["each_item"+ie] = items_xml.childNodes[0].childNodes[ie].childNodes;
this["each_item"+ie] = this["total_item"+ie]=this["each_item"+ie].length;
//
var bi = 0;
while (bi<this["total_item"+ie]) {
Thumb_img.push(this.items_xml.childNodes[0].childNodes[0].childNodes[bi].childNodes[0].childNodes);
//img_grande.push(this.items_xml.childNodes[0].childNodes[0].childNodes[bi].childNodes[1].childNodes);
eleccion_uno.push(this.items_xml.childNodes[0].childNodes[0].childNodes[bi].childNodes[2].childNodes);
eleccion_dos.push(this.items_xml.childNodes[0].childNodes[0].childNodes[bi].childNodes[3].childNodes);
eleccion_tres.push(this.items_xml.childNodes[0].childNodes[0].childNodes[bi].childNodes[4].childNodes);
eleccion_cuatro.push(this.items_xml.childNodes[0].childNodes[0].childNodes[bi].childNodes[5].childNodes);
eleccion_cinco.push(this.items_xml.childNodes[0].childNodes[0].childNodes[bi].childNodes[6].childNodes);
//trace(eleccion_uno[bi])
trace(bi)
bi++;
}////////// end item

numero_items.push(bi)
trace ("total item"+ie+": "+bi )
trace("----")
ie ++
}//end todos los items
trace("numero_items"+numero_items)

////////// Fin Array + XML
///////////////////////////////////////////////////////////////////////////////////////// Se Definen variables de los items
topDepth = total_item0
var_drop1 = -1
var_drop2 = -1
var_drop3 = -1
var_drop4 = -1
var_drop5 = -1
eleccion1 = "none"
eleccion2 = "none"
eleccion3 = "none"
eleccion4 = "none"
eleccion5 = "none"
///// end variables

//////////////////////////////////////////////////////////////////////////////////////////////////////////// Se crean los Items
function scroll_1(){
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// INICIO WHILE
var i:Number = 0;
trace("numero_items[i] "+numero_items[i])
num_items = numero_items[i]
while (i < num_items) {//this["total_item"+bi]) {
item.duplicateMovieClip("item"+i, i);
this["item"+i].i = i //le da un numero a cada movie
this["item"+i].backX = this["zona_inicial"+i]._x//////// on release variables
this["item"+i].backY = this["zona_inicial"+i]._y//////// on release variables

this["item"+i]._x = this["zona_inicial"+i]._x
this["item"+i]._y = this["zona_inicial"+i]._y
this["item"+i].imagen.drop.loadMovie(Thumb_img[i])

this["eleccion_uno"+i] = eleccion_uno[i] //////// define variables de drop/eleccion en none
this["eleccion_dos"+i] = eleccion_dos[i]
this["eleccion_tres"+i] = eleccion_tres[i]
this["eleccion_cuatro"+i] = eleccion_cuatro[i]
this["eleccion_cinco"+i] = eleccion_cinco[i]

/////////////////////////////////////////////////////////////////////////////////////////////// ON OVER
this["item"+i].boton.onRollOver = function(){

this._parent.onEnterFrame = function() {
if (this._currentframe != 24) {
this.nextFrame();
} else {
this.stop();
delete this["onEnterFrame"];
}
// end if
};
}

this["item"+i].boton.onRollOut = function(){
this._parent.onEnterFrame = function() {
if (this._currentframe != 15) {
this.prevFrame();
} else {
this.stop();
delete this["onEnterFrame"];
}
// end if
};
}
///// end on over

////////////////////////////////////////////////////////////////////////////////////////////// ON PRESS

this["item"+i].ease = 1.5; // porcentaje de suavizado del movieClip
///
this["item"+i].boton.onPress = function() { // on press
this._parent.drag = true; // llena variable del drag
this._parent.swapDepths(topDepth); //profundidad
++topDepth; //profundidad

if (var_drop1 == this._parent.i){
var_drop1 = -1
eleccion1 = "none"
}
if (var_drop2 == this._parent.i){
var_drop2 = -1
eleccion2 = "none"
}
if (var_drop3 == this._parent.i){
var_drop3 = -1
eleccion3 = "none"
}
if (var_drop4 == this._parent.i){
var_drop4 = -1
eleccion4 = "none"
}
if (var_drop5 == this._parent.i){
var_drop5 = -1
eleccion5 = "none"
}
if (Number(getTimer()-lastClick)<500) {
//trace("doble click")
} else {
lastClick = getTimer();
//trace("simple click")
}
};///// end on press

this["item"+i].dropCiclo.onEnterFrame = function() {////////////////////////////////////////// DRAG
if (this._parent.drag == true) { // chequea variable que activa el dragueo
this._parent.targX = _xmouse; // variable con la posicion del mouse
this._parent.targY = _ymouse; // variable con la posicion del mouse
}
if (this._parent._x != this._parent.targX | this._parent._y != this._parent.targY) { // suavizado del movieClip referente al mouse
this._parent._x += (this._parent.targX-this._parent._x)/this._parent.ease;
this._parent._y += (this._parent.targY-this._parent._y)/this._parent.ease;
}
};///// end Drag


this["item"+i].boton.onRelease = function() {///////////////////////////////////////////////////// ON RELEASE
this._parent.drag = false; // drag Stop
if (var_drop1 == -1 and this._parent.hitTest(papel1)){

this._parent._parent.eleccion1 = this._parent._parent["eleccion_uno"+this._parent.i] // variable eleccion correcta o incorrecta
this._parent.targX = papel1._x; // si esta en el papel blanco se queda
this._parent.targY = papel1._y;
var_drop1 = this._parent.i

} else if (var_drop2 == -1 and this._parent.hitTest(papel2)){

this._parent._parent.eleccion2 = this._parent._parent["eleccion_dos"+this._parent.i] // variable eleccion correcta o incorrecta
this._parent.targX = papel2._x; // si esta en el papel blanco se queda
this._parent.targY = papel2._y;
var_drop2 = this._parent.i

} else if (var_drop3 == -1 and this._parent.hitTest(papel3)){

this._parent._parent.eleccion3 = this._parent._parent["eleccion_tres"+this._parent.i] // variable eleccion correcta o incorrecta
this._parent.targX = papel3._x; // si esta en el papel blanco se queda
this._parent.targY = papel3._y;
var_drop3 = this._parent.i

} else if (var_drop4 == -1 and this._parent.hitTest(papel4)){

this._parent._parent.eleccion4 = this._parent._parent["eleccion_cuatro"+this._parent.i] // variable eleccion correcta o incorrecta
this._parent.targX = papel4._x; // si esta en el papel blanco se queda
this._parent.targY = papel4._y;
var_drop4 = this._parent.i

} else if (var_drop5 == -1 and this._parent.hitTest(papel5)){

this._parent._parent.eleccion5 = this._parent._parent["eleccion_cinco"+this._parent.i] // variable eleccion correcta o incorrecta
this._parent.targX = papel5._x; // si esta en el papel blanco se queda
this._parent.targY = papel5._y;
var_drop5 = this._parent.i

} else { // sino vuelve a la posicion inicial

this._parent.targX = this._parent.backX // la variable de donde tiene que volver se carga dentro del MC
this._parent.targY = this._parent.backY // la variable de donde tiene que volver se carga dentro del MC
}
};///// end on releas
i++;
} /////////////////////////End WHILE
} ///end scroll_1 function


//////////////////////////////////////////////////////////////////////////////////////////function items_salida
function items_salida() {
var ai:Number = 0;
trace ("items_salida")
while (ai < total_itemsScroll) {/////////// INICIO WHILE //total_itemsScroll se define el las flechas
this["item"+ai].onEnterFrame = function() {
if (this._currentframe != 1) {
this.prevFrame();
} else {
this.stop();
this.removeMovieClip();
delete this["onEnterFrame"];
if(flechaEnCurso == "si"){
if(scrollNumber == 1){
scroll_1()
flecha_der.gotoAndPlay("on");
flecha_izq.gotoAndStop("off");
flecha_der.btn._visible = true
}
if(scrollNumber == 2){
scroll_2()
flecha_der.gotoAndStop("off");
flecha_izq.gotoAndPlay("on");
flecha_izq.btn._visible = true
}
_global.flechaEnCurso = "no"
}
}
};
ai++;
}/////////////////////////End WHILE
}///// end function items_salida

Por stereo-tipo

10 de clabLevel



 

msie7

 

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