Foros del Web » Creando para Internet » Flash y Actionscript »

ActionScript en una instancia dinámica

Estas en el tema de ActionScript en una instancia dinámica en el foro de Flash y Actionscript en Foros del Web. El problema es este: en una película creo con ActionScript una serie de instancias de una MP, con duplicate movie. Ya que tengo, digamos, 6 ...
  #1 (permalink)  
Antiguo 06/06/2003, 16:50
Avatar de GhostRider  
Fecha de Ingreso: julio-2001
Ubicación: en mi propio infierno
Mensajes: 248
Antigüedad: 22 años, 8 meses
Puntos: 0
ActionScript en una instancia dinámica

El problema es este: en una película creo con ActionScript una serie de instancias de una MP, con duplicate movie.

Ya que tengo, digamos, 6 instancias de la MP quedan los nombres como dot1, dot2, etc.

Ahora, quiero asignarle un ActionScript a una sola de las instancias, algo como, para dot1:

onClipEvent (load) {
statements;
}

Cómo puedo hacerlo?

Nota: si no me supe explicar, porfavor díganme
  #2 (permalink)  
Antiguo 06/06/2003, 17:52
Avatar de TMeister
Crazy Coder
 
Fecha de Ingreso: enero-2002
Ubicación: En la Oficina
Mensajes: 2.880
Antigüedad: 22 años, 3 meses
Puntos: 193
Se me ocurre algo Asi:

Código:
for (i=0; i<6; i++) {
	this["dot"+i] = cuadro.duplicateMovieClip("dot"+i, i);
	this["dot"+i].label.text = i;
	this["dot"+i]._x = random(350);
	this["dot"+i]._y = random(350);
	if (i == 5) {
		this["dot"+i].onEnterFrame = function() {
			if (this._y<=500) {
				this._y += 10;
			} else {
				delete this.onEnterFrame;
			}
		};
	}
}
cuadro._visible = false;
Aqui le asignaras el EnterFrame al movieClip numero 5

Saludos!!
  #3 (permalink)  
Antiguo 09/06/2003, 22:38
Avatar de GhostRider  
Fecha de Ingreso: julio-2001
Ubicación: en mi propio infierno
Mensajes: 248
Antigüedad: 22 años, 8 meses
Puntos: 0
Pues no sale


a ver, aqui va de nuevo: tengo un simbolo "dot" que tiene este Action Script dentro del primer frame de la MP:

Código:
dragging = false;
onEnterFrame = function () {
	dx = 0;
	dy = 0;
	// sumerise the delta for all dots that are connected to this dot
	for (i=0; i<connected.length; i++) {
		dx += _root["dot"+connected[i]]._x-delta_x[i]-_x;
		dy += _root["dot"+connected[i]]._y-delta_y[i]-_y;
	}
	// if the current point is not dragged
	if (!dragging) {
		// if delta is very small negate it
		if (math.abs(dx)<1) {
			dx = 0;
		}
		if (math.abs(dy)<1) {
			dy = 0;
		}
		// vectors vx,vy are calculated in "elastic way"
		vx = vx*.84+dx*.14;
		vy = vy*.84+dy*.14;
		_x += vx;
		_y += vy;
		// bounce off the sides if needed
		if (_x>550 || _x<0) {
			vx = -vx;
			_x += vx;
		}
		if (_y>400 || _y<0) {
			vy = -vy;
			_y += vy;
		}
	}
};
onPress = function () {
	this.startDrag(false,0,0,550,400);
	this.dragging = true;
};
onRelease = function () {
	this.stopDrag();
	this.dragging = false;
	this.vx = 0;
	this.vy = 0;
};
y luego en el primer frame de scene1, entre muchas otras cosas, tengo esto:

Código:
if (newdot) {
		dots++;
		dotx[dots] = x;
		doty[dots] = y;
		duplicateMovieClip(dot, "dot"+dots, dots);
		_root["dot"+dots]._x = x;
		_root["dot"+dots]._y = y;
		_root["dot"+dots].connected = new array();
		_root["dot"+dots].delta_x = new array();
		_root["dot"+dots].delta_y = new array();
		
		if (dots == 2) {
			
			delete this["dot"+dots].onEnterFrame;
			
		
			this["dot"+dots].onLoad = function () {
				// declare and set initial variables and properties
				speed = 1;
			}

			this["dot"+dots].onEnterFrame = function() {
				gotoSpotX = _root._xmouse;
				gotoSpotY = _root._ymouse;
				dif_x = _x-gotoSpotX;
				dif_y = _y-gotoSpotY;
				targetRotation = -Math.atan2(dif_x, dif_y)/(Math.PI/180);
				_rotation = targetRotation;

				// move beetle toward the target and stop when it gets there
				if (Math.sqrt((dif_x*dif_x)+(dif_y*dif_y))>speed) {
					_y -= speed*Math.cos(_rotation*(Math.PI/180));
					_x += speed*Math.sin(_rotation*(Math.PI/180));
				}
	
			}
		}
		
       }

La parte que esta dentro de

if (dots == 2) {
}


es la que añadí segun su consejo, es decir, lo que quiero es que en vez de seguir el mouse con dragging, lo siga con el código, pero solo un punto de los que se crean.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:49.