Arrastrar objetos múltiples de un objetivo?

  • chibuki
  • Novice
  • Novice
  • No Avatar
  • Registrado: Oct 18, 2008
  • Mensajes: 22
  • Status: Offline

Nota Septiembre 2nd, 2009, 9:16 am

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).
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Septiembre 2nd, 2009, 9:16 am

  • IceCold
  • Guru
  • Guru
  • Avatar de Usuario
  • Registrado: Nov 05, 2004
  • Mensajes: 1254
  • Loc: Ro
  • Status: Offline

Nota Septiembre 3rd, 2009, 1:49 am

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í:
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");
        }
    }
}
  1. function mouseReleasedHandler(e:MouseEvent):void {
  2.     dragging = false;
  3.     if (!thumb1_mc.dropped)
  4.     {
  5.         if (thumb1_mc.hitTestPoint(mcDropPoint.x, mcDropPoint.y))
  6.         {
  7.             thumb1_mc.dropped = true;
  8.             loadGallery("galleryinteraction1.swf");
  9.         }
  10.     }
  11. }

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);
}
  1. function loadGallery(urlPath)
  2. {
  3.     imageLoader.unload();
  4.     var imageRequest:URLRequest = new URLRequest(urlPath);
  5.     imageLoader.load(imageRequest);
  6.     imageLoader.y = 59;
  7.     addChild(imageLoader);
  8. }


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);
}
  1. var urlPaths:Array = Array("movie1.swf", "movie2.swf", ...., "movieX.swf" )
  2. var crtDraggedObject:MovieClip = null;
  3. var crtObject:MovieClip;
  4. for (var objIndex = 0; objIndex < objCount; objIndex++)
  5. {
  6.    crtObject = this.getChildByName("thumb"+objIndex+"_mc") as MovieClip;
  7.    crtObject.dropped = false;
  8.    crtObject.dragging = false;
  9.    crtObject.urlPath = urlPaths[objIndex];
  10.    crtObject.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
  11. }


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;
}
  1. function mouseDownHandler(e:MouseEvent):void {
  2.   crtDraggedObject = e.target as MovieClip;
  3.   dragging = true;
  4.   crtDraggedObject.dropped = false;
  5. }


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
  • Novice
  • No Avatar
  • Registrado: Oct 18, 2008
  • Mensajes: 22
  • Status: Offline

Nota Septiembre 3rd, 2009, 5:29 am

¡Gracias!! Eso es el billete. :mrgreen:

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));
    }
}
  1. var urlPaths:Array = Array("gallery1.swf", "gallery2.swf", "gallery3.swf", "gallery4.swf");
  2. var crtDraggedObject:MovieClip = null;
  3. var crtObject:MovieClip;
  4. for (var objIndex = 0; objIndex < objCount; objIndex++) {
  5.     crtObject = this.getChildByName("thumb"+objIndex+"_mc") as MovieClip;
  6.     crtObject.dropped = false;
  7.     crtObject.dragging = false;
  8.     crtObject.urlPath = urlPaths[objIndex];
  9.     crtObject.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
  10. }
  11. var imageLoader:Loader = new Loader();
  12. function loadGallery(urlPath) {
  13.     imageLoader.unload();
  14.     var imageRequest:URLRequest = new URLRequest(urlPath);
  15.     imageLoader.load(imageRequest);
  16.     imageLoader.y = 59;
  17.     addChild(imageLoader);
  18. }
  19. /**********************************************************************/
  20. //This variable tells whether the user is dragging or not
  21. var dragging:Boolean = false;
  22. //Spring variable (how strong the spring effect is)
  23. var springFactor:Number = 0.2;
  24. //Friction for the animatiom
  25. var friction:Number = 0.59;//originally 0.9
  26. //x and y speeds
  27. var speedX:Number = 0.0005;//originally 0
  28. var speedY:Number = 0.0005;//originally 0
  29. //acceleration for x and y speeds
  30. var accX:Number = 0.0005;
  31. var accY:Number = 0.0005;
  32. //Overall speed
  33. var speed:Number = 0.5;//originally 10
  34. //Add event listeners for the MOUSE_DOWN and MOUSE_UP
  35. //events, so we know when to start/stop dragging.
  36. crtDraggedObject.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
  37. stage.addEventListener(MouseEvent.MOUSE_UP, mouseReleasedHandler);
  38. //Add ENTER_FRAME which animates the ball movement
  39. addEventListener(Event.ENTER_FRAME, moveBall1);
  40. //This function is called when the user presses the mouse on the ball
  41. function mouseDownHandler(e:MouseEvent):void {
  42.     crtDraggedObject = e.target as MovieClip;
  43.     dragging = true;
  44.     crtDraggedObject.dropped = false;
  45. }
  46. //This function is called when the user releases the mouse
  47. function mouseReleasedHandler(e:MouseEvent):void {
  48.     dragging = false;
  49.     if (!crtDraggedObject.dropped) {
  50.         if (crtDraggedObject.hitTestPoint(mcDropPoint.x, mcDropPoint.y)) {
  51.             crtDraggedObject.dropped = true;
  52.             loadGallery("galleryinteraction1.swf");
  53.         }
  54.     }
  55. }
  56. function moveBall1(event:Event):void {
  57.     //We only move the ball when the user is dragging
  58.     if (dragging) {
  59.         //Calculate the x and y distances from the ball to the mouse
  60.         var distanceX:Number = mouseX - crtDraggedObject.x;
  61.         var distanceY:Number = mouseY - crtDraggedObject.y;
  62.         //Update x and y accelerations
  63.         accX = distanceX * springFactor;
  64.         accY = distanceY * springFactor;
  65.         //Add the acceleration to the speed
  66.         speedX += accX;
  67.         speedY += accY;
  68.         //Add friction, otherwise the animation
  69.         //would go on forever.
  70.         speedX *= friction;
  71.         speedY *= friction;
  72.         //Move the ball to the new coordinates (closer to the mouse)
  73.         crtDraggedObject.x += speedX;
  74.         crtDraggedObject.y += speedY;
  75.     }
  76. }
  77. /**********************************************************************/
  78. //We use this timer to create a trail ball each 0.03 seconds
  79. var timer:Timer = new Timer(10,1400000);//originally 30,400000
  80. timer.addEventListener(TimerEvent.TIMER, createTrailBall);
  81. timer.start();
  82. //This function is called by the timer
  83. function createTrailBall(e:Event):void {
  84.     crtDraggedObject = null;
  85.     
  86.     //Create a new ball instance
  87.     var trailBall1:Ball1=new Ball1();
  88.     //Position the trail ball in the same position where the original ball is located
  89.     trailBall1.x = crtDraggedObject.x;
  90.     trailBall1.y = crtDraggedObject.y;
  91.     //Add ENTER_FRAME to animate the trail ball
  92.     trailBall1.addEventListener(Event.ENTER_FRAME,animateTrailBall);
  93.     /*
  94.     Add the trail ball on to the stage.
  95.     We don't want to position the trail ball on top of the original ball.
  96.     We use the addChildAt method to set the index to 0.
  97.     */
  98.     addChildAt(trailBall1,0);
  99. }
  100. function animateTrailBall(e:Event):void {
  101.     //In each frame, reduce the alpha and the scale of the trail ball.
  102.     e.target.alpha -= 0.1;
  103.     e.target.scaleY -= 0.1;
  104.     e.target.scaleX -= 0.1;
  105.     /*
  106.     If the alpha is less than 0, we remove the trail ball from the
  107.     stage.
  108.     */
  109.     if (e.target.alpha < 0) {
  110.         e.target.removeEventListener(Event.ENTER_FRAME,animateTrailBall);
  111.         removeChild((MovieClip)(e.target));
  112.     }
  113. }
  • IceCold
  • Guru
  • Guru
  • Avatar de Usuario
  • Registrado: Nov 05, 2004
  • Mensajes: 1254
  • Loc: Ro
  • Status: Offline

Nota Septiembre 4th, 2009, 6:55 am

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. ”

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
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC