Arrastrar objetos múltiples de un objetivo?
- chibuki
- Novice


- Registrado: Oct 18, 2008
- Mensajes: 22
- Status: Offline
Hola,
Im que hace una especie de galería única, donde habrá una decena de miniaturas flotando alrededor de una gota en el punto medio. Cada una de esas miniatura flotante representa una galería de fotos de unos pocos. Cuando la imagen es arrastrado a ese lugar gota, un archivo de Flash se carga ahí utilizando ImageLoader. Debería haber un botón de cierre para descargar también.
Tengo las obras arrastrando pero todavía no puede hacer que se cargue la película, cuando su puesto en el lugar gota. Y el problema es, ¿cómo puedo trabajar con varios objetos (las imágenes flotantes) con un solo objetivo (el punto de caída)?
Tengo un archivo de ejemplo en: http : / / www . M egaupload . com /? d = 5LPL09TY
Si elimina los comentarios en el primer bloque de código, itll demostrar cómo las cargas de película con ImageLoader (pero es el ratón).
Im que hace una especie de galería única, donde habrá una decena de miniaturas flotando alrededor de una gota en el punto medio. Cada una de esas miniatura flotante representa una galería de fotos de unos pocos. Cuando la imagen es arrastrado a ese lugar gota, un archivo de Flash se carga ahí utilizando ImageLoader. Debería haber un botón de cierre para descargar también.
Tengo las obras arrastrando pero todavía no puede hacer que se cargue la película, cuando su puesto en el lugar gota. Y el problema es, ¿cómo puedo trabajar con varios objetos (las imágenes flotantes) con un solo objetivo (el punto de caída)?
Tengo un archivo de ejemplo en: http : / / www . M egaupload . com /? d = 5LPL09TY
Si elimina los comentarios en el primer bloque de código, itll demostrar cómo las cargas de película con ImageLoader (pero es el ratón).
- Anonymous
- Bot


- Registrado: 25 Feb 2008
- Mensajes: ?
- Loc: Ozzuland
- Status: Online
Septiembre 2nd, 2009, 9:16 am
- IceCold
- Guru


- Registrado: Nov 05, 2004
- Mensajes: 1254
- Loc: Ro
- Status: Offline
Su no es tan difícil hacer eso.
Caer en un objetivo significa sólo para comprobar el lanzamiento del ratón si el movieclip arrastrado se solapa con la meta bajando.
de modo que su función de liberación del ratón se vería así:
Para ello, tiene que declarar thumb1_mc.dropped = false; (en cualquier parte del código, no sólo en una función: p) y le dará un nombre de instancia el destino de colocación (en este caso: mcDropPoint).
También ajustar su loadGallery1 función a parecerse
Para los múltiples objetos, hay que ajustar un poco el código, de modo que usted puede hacer todas las declaraciones y controles en un bucle.
Algo como:
luego en el mouseDownHandler, necesita para obtener la película de destino, para saber que el pulgar está arrastrando.
y en su función mouseReleasedHandler actual, sustituir thumb1_mc con crtDraggedObject;
Mismo cambio que realice en moveBall1 y createTrailBall. También en createTrailBall, compruebe primero si crtDraggedObject es nulo, a continuación, volver de la función.
Eso es todo.
Caer en un objetivo significa sólo para comprobar el lanzamiento del ratón si el movieclip arrastrado se solapa con la meta bajando.
de modo que su función de liberación del ratón se vería así:
Código: [ Select ]
function mouseReleasedHandler(e:MouseEvent):void {
dragging = false;
if (!thumb1_mc.dropped)
{
if (thumb1_mc.hitTestPoint(mcDropPoint.x, mcDropPoint.y))
{
thumb1_mc.dropped = true;
loadGallery("galleryinteraction1.swf");
}
}
}
dragging = false;
if (!thumb1_mc.dropped)
{
if (thumb1_mc.hitTestPoint(mcDropPoint.x, mcDropPoint.y))
{
thumb1_mc.dropped = true;
loadGallery("galleryinteraction1.swf");
}
}
}
- function mouseReleasedHandler(e:MouseEvent):void {
- dragging = false;
- if (!thumb1_mc.dropped)
- {
- if (thumb1_mc.hitTestPoint(mcDropPoint.x, mcDropPoint.y))
- {
- thumb1_mc.dropped = true;
- loadGallery("galleryinteraction1.swf");
- }
- }
- }
Para ello, tiene que declarar thumb1_mc.dropped = false; (en cualquier parte del código, no sólo en una función: p) y le dará un nombre de instancia el destino de colocación (en este caso: mcDropPoint).
También ajustar su loadGallery1 función a parecerse
Código: [ Select ]
function loadGallery(urlPath)
{
imageLoader.unload();
var imageRequest:URLRequest = new URLRequest(urlPath);
imageLoader.load(imageRequest);
imageLoader.y = 59;
addChild(imageLoader);
}
{
imageLoader.unload();
var imageRequest:URLRequest = new URLRequest(urlPath);
imageLoader.load(imageRequest);
imageLoader.y = 59;
addChild(imageLoader);
}
- function loadGallery(urlPath)
- {
- imageLoader.unload();
- var imageRequest:URLRequest = new URLRequest(urlPath);
- imageLoader.load(imageRequest);
- imageLoader.y = 59;
- addChild(imageLoader);
- }
Para los múltiples objetos, hay que ajustar un poco el código, de modo que usted puede hacer todas las declaraciones y controles en un bucle.
Algo como:
Código: [ Select ]
var urlPaths:Array = Array("movie1.swf", "movie2.swf", ...., "movieX.swf" )
var crtDraggedObject:MovieClip = null;
var crtObject:MovieClip;
for (var objIndex = 0; objIndex < objCount; objIndex++)
{
crtObject = this.getChildByName("thumb"+objIndex+"_mc") as MovieClip;
crtObject.dropped = false;
crtObject.dragging = false;
crtObject.urlPath = urlPaths[objIndex];
crtObject.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
}
var crtDraggedObject:MovieClip = null;
var crtObject:MovieClip;
for (var objIndex = 0; objIndex < objCount; objIndex++)
{
crtObject = this.getChildByName("thumb"+objIndex+"_mc") as MovieClip;
crtObject.dropped = false;
crtObject.dragging = false;
crtObject.urlPath = urlPaths[objIndex];
crtObject.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
}
- var urlPaths:Array = Array("movie1.swf", "movie2.swf", ...., "movieX.swf" )
- var crtDraggedObject:MovieClip = null;
- var crtObject:MovieClip;
- for (var objIndex = 0; objIndex < objCount; objIndex++)
- {
- crtObject = this.getChildByName("thumb"+objIndex+"_mc") as MovieClip;
- crtObject.dropped = false;
- crtObject.dragging = false;
- crtObject.urlPath = urlPaths[objIndex];
- crtObject.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
- }
luego en el mouseDownHandler, necesita para obtener la película de destino, para saber que el pulgar está arrastrando.
Código: [ Select ]
function mouseDownHandler(e:MouseEvent):void {
crtDraggedObject = e.target as MovieClip;
dragging = true;
crtDraggedObject.dropped = false;
}
crtDraggedObject = e.target as MovieClip;
dragging = true;
crtDraggedObject.dropped = false;
}
- function mouseDownHandler(e:MouseEvent):void {
- crtDraggedObject = e.target as MovieClip;
- dragging = true;
- crtDraggedObject.dropped = false;
- }
y en su función mouseReleasedHandler actual, sustituir thumb1_mc con crtDraggedObject;
Mismo cambio que realice en moveBall1 y createTrailBall. También en createTrailBall, compruebe primero si crtDraggedObject es nulo, a continuación, volver de la función.
Eso es todo.
“True mastery transcede any particular art. It stems from mastery of oneself - the ability, developed throgh self-discipline, to be calm, fully aware, and complety in tune with oneself and the surroundings. Then, and only then, can a person know himself. ”
- chibuki
- Novice


- Registrado: Oct 18, 2008
- Mensajes: 22
- Status: Offline
¡Gracias!! Eso es el billete. 
Veo la coloca en una matriz es la mejor manera de hacer esto. I nombre de todos mis archivos de la galería swf a gallery1.swf, gallery2.swf, y así sucesivamente. He estado jugando con los códigos de ahora, las obras de arrastre para la galería, pero ahora me encontré con dos errores:
Descripción: 1137: Número incorrecto de argumentos. No esperaba más de 1.
Fuente: urlPaths var: Array = Array ( "gallery1.swf", "gallery2.swf", "gallery3.swf", "gallery4.swf"),
Descripción: 1120: El acceso de los objCount propiedad no definida.
Fuente: for (var objIndex = 0; objIndex <objCount; objIndex + +)
No entiendo por qué dice que espera que no más de 1. I pensar He cambiado thumb1_mc para crtDraggedObject en todas partes, no soy seguro de si iba a hacer eso.
Además, ¿por qué no me puedo mover las burbujas de otros ahora, como thumb2_mc?
Por último, wouldnt de I necesidad de modificar loadGallery en mi mouseReleasedHandler la función después de la secuencia de comandos de varios objetos está en su lugar?
Heres mi script parece ahora:
Veo la coloca en una matriz es la mejor manera de hacer esto. I nombre de todos mis archivos de la galería swf a gallery1.swf, gallery2.swf, y así sucesivamente. He estado jugando con los códigos de ahora, las obras de arrastre para la galería, pero ahora me encontré con dos errores:
Descripción: 1137: Número incorrecto de argumentos. No esperaba más de 1.
Fuente: urlPaths var: Array = Array ( "gallery1.swf", "gallery2.swf", "gallery3.swf", "gallery4.swf"),
Descripción: 1120: El acceso de los objCount propiedad no definida.
Fuente: for (var objIndex = 0; objIndex <objCount; objIndex + +)
No entiendo por qué dice que espera que no más de 1. I pensar He cambiado thumb1_mc para crtDraggedObject en todas partes, no soy seguro de si iba a hacer eso.
Además, ¿por qué no me puedo mover las burbujas de otros ahora, como thumb2_mc?
Por último, wouldnt de I necesidad de modificar loadGallery en mi mouseReleasedHandler la función después de la secuencia de comandos de varios objetos está en su lugar?
Heres mi script parece ahora:
Código: [ Select ]
var urlPaths:Array = Array("gallery1.swf", "gallery2.swf", "gallery3.swf", "gallery4.swf");
var crtDraggedObject:MovieClip = null;
var crtObject:MovieClip;
for (var objIndex = 0; objIndex < objCount; objIndex++) {
crtObject = this.getChildByName("thumb"+objIndex+"_mc") as MovieClip;
crtObject.dropped = false;
crtObject.dragging = false;
crtObject.urlPath = urlPaths[objIndex];
crtObject.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
}
var imageLoader:Loader = new Loader();
function loadGallery(urlPath) {
imageLoader.unload();
var imageRequest:URLRequest = new URLRequest(urlPath);
imageLoader.load(imageRequest);
imageLoader.y = 59;
addChild(imageLoader);
}
/**********************************************************************/
//This variable tells whether the user is dragging or not
var dragging:Boolean = false;
//Spring variable (how strong the spring effect is)
var springFactor:Number = 0.2;
//Friction for the animatiom
var friction:Number = 0.59;//originally 0.9
//x and y speeds
var speedX:Number = 0.0005;//originally 0
var speedY:Number = 0.0005;//originally 0
//acceleration for x and y speeds
var accX:Number = 0.0005;
var accY:Number = 0.0005;
//Overall speed
var speed:Number = 0.5;//originally 10
//Add event listeners for the MOUSE_DOWN and MOUSE_UP
//events, so we know when to start/stop dragging.
crtDraggedObject.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
stage.addEventListener(MouseEvent.MOUSE_UP, mouseReleasedHandler);
//Add ENTER_FRAME which animates the ball movement
addEventListener(Event.ENTER_FRAME, moveBall1);
//This function is called when the user presses the mouse on the ball
function mouseDownHandler(e:MouseEvent):void {
crtDraggedObject = e.target as MovieClip;
dragging = true;
crtDraggedObject.dropped = false;
}
//This function is called when the user releases the mouse
function mouseReleasedHandler(e:MouseEvent):void {
dragging = false;
if (!crtDraggedObject.dropped) {
if (crtDraggedObject.hitTestPoint(mcDropPoint.x, mcDropPoint.y)) {
crtDraggedObject.dropped = true;
loadGallery("galleryinteraction1.swf");
}
}
}
function moveBall1(event:Event):void {
//We only move the ball when the user is dragging
if (dragging) {
//Calculate the x and y distances from the ball to the mouse
var distanceX:Number = mouseX - crtDraggedObject.x;
var distanceY:Number = mouseY - crtDraggedObject.y;
//Update x and y accelerations
accX = distanceX * springFactor;
accY = distanceY * springFactor;
//Add the acceleration to the speed
speedX += accX;
speedY += accY;
//Add friction, otherwise the animation
//would go on forever.
speedX *= friction;
speedY *= friction;
//Move the ball to the new coordinates (closer to the mouse)
crtDraggedObject.x += speedX;
crtDraggedObject.y += speedY;
}
}
/**********************************************************************/
//We use this timer to create a trail ball each 0.03 seconds
var timer:Timer = new Timer(10,1400000);//originally 30,400000
timer.addEventListener(TimerEvent.TIMER, createTrailBall);
timer.start();
//This function is called by the timer
function createTrailBall(e:Event):void {
crtDraggedObject = null;
//Create a new ball instance
var trailBall1:Ball1=new Ball1();
//Position the trail ball in the same position where the original ball is located
trailBall1.x = crtDraggedObject.x;
trailBall1.y = crtDraggedObject.y;
//Add ENTER_FRAME to animate the trail ball
trailBall1.addEventListener(Event.ENTER_FRAME,animateTrailBall);
/*
Add the trail ball on to the stage.
We don't want to position the trail ball on top of the original ball.
We use the addChildAt method to set the index to 0.
*/
addChildAt(trailBall1,0);
}
function animateTrailBall(e:Event):void {
//In each frame, reduce the alpha and the scale of the trail ball.
e.target.alpha -= 0.1;
e.target.scaleY -= 0.1;
e.target.scaleX -= 0.1;
/*
If the alpha is less than 0, we remove the trail ball from the
stage.
*/
if (e.target.alpha < 0) {
e.target.removeEventListener(Event.ENTER_FRAME,animateTrailBall);
removeChild((MovieClip)(e.target));
}
}
var crtDraggedObject:MovieClip = null;
var crtObject:MovieClip;
for (var objIndex = 0; objIndex < objCount; objIndex++) {
crtObject = this.getChildByName("thumb"+objIndex+"_mc") as MovieClip;
crtObject.dropped = false;
crtObject.dragging = false;
crtObject.urlPath = urlPaths[objIndex];
crtObject.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
}
var imageLoader:Loader = new Loader();
function loadGallery(urlPath) {
imageLoader.unload();
var imageRequest:URLRequest = new URLRequest(urlPath);
imageLoader.load(imageRequest);
imageLoader.y = 59;
addChild(imageLoader);
}
/**********************************************************************/
//This variable tells whether the user is dragging or not
var dragging:Boolean = false;
//Spring variable (how strong the spring effect is)
var springFactor:Number = 0.2;
//Friction for the animatiom
var friction:Number = 0.59;//originally 0.9
//x and y speeds
var speedX:Number = 0.0005;//originally 0
var speedY:Number = 0.0005;//originally 0
//acceleration for x and y speeds
var accX:Number = 0.0005;
var accY:Number = 0.0005;
//Overall speed
var speed:Number = 0.5;//originally 10
//Add event listeners for the MOUSE_DOWN and MOUSE_UP
//events, so we know when to start/stop dragging.
crtDraggedObject.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
stage.addEventListener(MouseEvent.MOUSE_UP, mouseReleasedHandler);
//Add ENTER_FRAME which animates the ball movement
addEventListener(Event.ENTER_FRAME, moveBall1);
//This function is called when the user presses the mouse on the ball
function mouseDownHandler(e:MouseEvent):void {
crtDraggedObject = e.target as MovieClip;
dragging = true;
crtDraggedObject.dropped = false;
}
//This function is called when the user releases the mouse
function mouseReleasedHandler(e:MouseEvent):void {
dragging = false;
if (!crtDraggedObject.dropped) {
if (crtDraggedObject.hitTestPoint(mcDropPoint.x, mcDropPoint.y)) {
crtDraggedObject.dropped = true;
loadGallery("galleryinteraction1.swf");
}
}
}
function moveBall1(event:Event):void {
//We only move the ball when the user is dragging
if (dragging) {
//Calculate the x and y distances from the ball to the mouse
var distanceX:Number = mouseX - crtDraggedObject.x;
var distanceY:Number = mouseY - crtDraggedObject.y;
//Update x and y accelerations
accX = distanceX * springFactor;
accY = distanceY * springFactor;
//Add the acceleration to the speed
speedX += accX;
speedY += accY;
//Add friction, otherwise the animation
//would go on forever.
speedX *= friction;
speedY *= friction;
//Move the ball to the new coordinates (closer to the mouse)
crtDraggedObject.x += speedX;
crtDraggedObject.y += speedY;
}
}
/**********************************************************************/
//We use this timer to create a trail ball each 0.03 seconds
var timer:Timer = new Timer(10,1400000);//originally 30,400000
timer.addEventListener(TimerEvent.TIMER, createTrailBall);
timer.start();
//This function is called by the timer
function createTrailBall(e:Event):void {
crtDraggedObject = null;
//Create a new ball instance
var trailBall1:Ball1=new Ball1();
//Position the trail ball in the same position where the original ball is located
trailBall1.x = crtDraggedObject.x;
trailBall1.y = crtDraggedObject.y;
//Add ENTER_FRAME to animate the trail ball
trailBall1.addEventListener(Event.ENTER_FRAME,animateTrailBall);
/*
Add the trail ball on to the stage.
We don't want to position the trail ball on top of the original ball.
We use the addChildAt method to set the index to 0.
*/
addChildAt(trailBall1,0);
}
function animateTrailBall(e:Event):void {
//In each frame, reduce the alpha and the scale of the trail ball.
e.target.alpha -= 0.1;
e.target.scaleY -= 0.1;
e.target.scaleX -= 0.1;
/*
If the alpha is less than 0, we remove the trail ball from the
stage.
*/
if (e.target.alpha < 0) {
e.target.removeEventListener(Event.ENTER_FRAME,animateTrailBall);
removeChild((MovieClip)(e.target));
}
}
- var urlPaths:Array = Array("gallery1.swf", "gallery2.swf", "gallery3.swf", "gallery4.swf");
- var crtDraggedObject:MovieClip = null;
- var crtObject:MovieClip;
- for (var objIndex = 0; objIndex < objCount; objIndex++) {
- crtObject = this.getChildByName("thumb"+objIndex+"_mc") as MovieClip;
- crtObject.dropped = false;
- crtObject.dragging = false;
- crtObject.urlPath = urlPaths[objIndex];
- crtObject.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
- }
- var imageLoader:Loader = new Loader();
- function loadGallery(urlPath) {
- imageLoader.unload();
- var imageRequest:URLRequest = new URLRequest(urlPath);
- imageLoader.load(imageRequest);
- imageLoader.y = 59;
- addChild(imageLoader);
- }
- /**********************************************************************/
- //This variable tells whether the user is dragging or not
- var dragging:Boolean = false;
- //Spring variable (how strong the spring effect is)
- var springFactor:Number = 0.2;
- //Friction for the animatiom
- var friction:Number = 0.59;//originally 0.9
- //x and y speeds
- var speedX:Number = 0.0005;//originally 0
- var speedY:Number = 0.0005;//originally 0
- //acceleration for x and y speeds
- var accX:Number = 0.0005;
- var accY:Number = 0.0005;
- //Overall speed
- var speed:Number = 0.5;//originally 10
- //Add event listeners for the MOUSE_DOWN and MOUSE_UP
- //events, so we know when to start/stop dragging.
- crtDraggedObject.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
- stage.addEventListener(MouseEvent.MOUSE_UP, mouseReleasedHandler);
- //Add ENTER_FRAME which animates the ball movement
- addEventListener(Event.ENTER_FRAME, moveBall1);
- //This function is called when the user presses the mouse on the ball
- function mouseDownHandler(e:MouseEvent):void {
- crtDraggedObject = e.target as MovieClip;
- dragging = true;
- crtDraggedObject.dropped = false;
- }
- //This function is called when the user releases the mouse
- function mouseReleasedHandler(e:MouseEvent):void {
- dragging = false;
- if (!crtDraggedObject.dropped) {
- if (crtDraggedObject.hitTestPoint(mcDropPoint.x, mcDropPoint.y)) {
- crtDraggedObject.dropped = true;
- loadGallery("galleryinteraction1.swf");
- }
- }
- }
- function moveBall1(event:Event):void {
- //We only move the ball when the user is dragging
- if (dragging) {
- //Calculate the x and y distances from the ball to the mouse
- var distanceX:Number = mouseX - crtDraggedObject.x;
- var distanceY:Number = mouseY - crtDraggedObject.y;
- //Update x and y accelerations
- accX = distanceX * springFactor;
- accY = distanceY * springFactor;
- //Add the acceleration to the speed
- speedX += accX;
- speedY += accY;
- //Add friction, otherwise the animation
- //would go on forever.
- speedX *= friction;
- speedY *= friction;
- //Move the ball to the new coordinates (closer to the mouse)
- crtDraggedObject.x += speedX;
- crtDraggedObject.y += speedY;
- }
- }
- /**********************************************************************/
- //We use this timer to create a trail ball each 0.03 seconds
- var timer:Timer = new Timer(10,1400000);//originally 30,400000
- timer.addEventListener(TimerEvent.TIMER, createTrailBall);
- timer.start();
- //This function is called by the timer
- function createTrailBall(e:Event):void {
- crtDraggedObject = null;
- //Create a new ball instance
- var trailBall1:Ball1=new Ball1();
- //Position the trail ball in the same position where the original ball is located
- trailBall1.x = crtDraggedObject.x;
- trailBall1.y = crtDraggedObject.y;
- //Add ENTER_FRAME to animate the trail ball
- trailBall1.addEventListener(Event.ENTER_FRAME,animateTrailBall);
- /*
- Add the trail ball on to the stage.
- We don't want to position the trail ball on top of the original ball.
- We use the addChildAt method to set the index to 0.
- */
- addChildAt(trailBall1,0);
- }
- function animateTrailBall(e:Event):void {
- //In each frame, reduce the alpha and the scale of the trail ball.
- e.target.alpha -= 0.1;
- e.target.scaleY -= 0.1;
- e.target.scaleX -= 0.1;
- /*
- If the alpha is less than 0, we remove the trail ball from the
- stage.
- */
- if (e.target.alpha < 0) {
- e.target.removeEventListener(Event.ENTER_FRAME,animateTrailBall);
- removeChild((MovieClip)(e.target));
- }
- }
- IceCold
- Guru


- Registrado: Nov 05, 2004
- Mensajes: 1254
- Loc: Ro
- Status: Offline
Me acaba de proporcionar algunas pistas, no el código exacto de la vista previa múltiple. Simplemente hacer un buen uso de tu mente y poner juntos. Im seguro usted puede hacer eso.
“True mastery transcede any particular art. It stems from mastery of oneself - the ability, developed throgh self-discipline, to be calm, fully aware, and complety in tune with oneself and the surroundings. Then, and only then, can a person know himself. ”
Página 1 de 1
Para responder a este tema que necesita para ingresar o registrarse. Es gratis.
Publicar Información
- Total de mensajes en este tema: 4 mensajes
- Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 48 invitados
- No puede abrir nuevos temas en este Foro
- No puede responder a temas en este Foro
- No puede editar sus mensajes en este Foro
- No puede borrar sus mensajes en este Foro
- No puede enviar adjuntos en este Foro
