Faire glisser les objets sur un même cible?

  • chibuki
  • Novice
  • Novice
  • No Avatar
  • Inscription: Oct 18, 2008
  • Messages: 22
  • Status: Offline

Message Septembre 2nd, 2009, 9:16 am

Bonjour,

Im faisant une sorte de galerie d'art unique, où il y aura une douzaine de vignettes flottant autour d'une place déroulant dans le milieu. Chacun de ces aperçu flottant représente une galerie de quelques photos. Lorsque la vignette est déplacé à cet endroit à goutte, un nouveau fichier Flash se charge juste là en utilisant chargeurImage. Il devrait y avoir un bouton de fermeture pour décharger aussi.

J'ai l'usine traîne, mais je n'arrive toujours pas à le charger le film lorsque sa mise en place goutte. Et le problème est, comment puis-je travailler avec des objets multiples (l'image flottante) avec un seul objectif (l'endroit de chute)?

J'ai un fichier d'exemple à l'adresse: http : / / www . m egaupload . com /? d = 5LPL09TY

Si vous supprimez les commentaires dans le premier bloc de code, itll démontrer comment les charges d'animation en utilisant chargeurImage (mais il est sur la souris).
  • Anonymous
  • Bot
  • No Avatar
  • Inscription: 25 Feb 2008
  • Messages: ?
  • Loc: Ozzuland
  • Status: Online

Message Septembre 2nd, 2009, 9:16 am

  • IceCold
  • Guru
  • Guru
  • Avatar de l’utilisateur
  • Inscription: Nov 05, 2004
  • Messages: 1254
  • Loc: Ro
  • Status: Offline

Message Septembre 3rd, 2009, 1:49 am

Ce n'est pas si difficile de le faire.
En tombant sur une cible signifie simplement pour vérifier si la libération de la souris MovieClip traîné chevauchements l'objectif de baisse.
si votre fonction de libération de la souris pourrait ressembler:
Code: [ 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. }

Pour cela, vous devez déclarer thumb1_mc.dropped = false; (n'importe où dans le code, mais pas dans une fonction: p), et de donner un nom d'instance la cible de dépôt (dans ce cas: mcDropPoint).
Également ajuster votre loadGallery1 fonction de ressembler à
Code: [ 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. }


Pour les objets multiples, dont vous avez besoin d'ajuster un peu votre code, de sorte que vous pouvez faire toutes les déclarations et contrôles en boucle.
Quelque chose comme:
Code: [ 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. }


puis dans la mouseDownHandler, vous avez besoin pour obtenir le film cible, à savoir le pouce qui est actuellement traîné.
Code: [ 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. }


et dans votre fonction actuelle mouseReleasedHandler, remplacer thumb1_mc avec crtDraggedObject;
Mêmes changements que vous effectuez dans moveBall1 et createTrailBall. Toujours en createTrailBall, vérifiez d'abord si crtDraggedObject est nulle, puis retour de la fonction.
Thats all.
“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
  • Inscription: Oct 18, 2008
  • Messages: 22
  • Status: Offline

Message Septembre 3rd, 2009, 5:29 am

Merci! Thats le billet. :mrgreen:

Je vois en la plaçant dans un tableau est la meilleure façon le faire. J'ai renommé tous mes fichiers de la galerie swf à gallery1.swf, gallery2.swf, et ainsi de suite. Ive été à jouer avec les codes maintenant, les ouvrages faisant glisser pour la première galerie, mais maintenant, j'ai rencontré deux erreurs:

Description: 1137: nombre incorrect d'arguments. Ne s'attendait pas à plus de 1.
Source: urlPaths var: Array = Array ( "gallery1.swf", "gallery2.swf", "gallery3.swf", "gallery4.swf")

Description: 1120: Accès des objCount propriété non définie.
Source: pour (objindex var = 0; objindex <objCount; objindex + +)


Je ne comprends pas pourquoi il dit ne s'attendait pas à plus de 1. Je penser J'ai changé thumb1_mc à crtDraggedObject partout, Im ne sais pas si je devais le faire.

Aussi, pourquoi je ne peux pas déplacer les bulles d'autres, maintenant, comme thumb2_mc?

Enfin, wouldnt Je dois modifier dans ma loadGallery mouseReleasedHandler fonction après les multiples objets de script est en place?

Heres mon script ressemble maintenant:
Code: [ 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 l’utilisateur
  • Inscription: Nov 05, 2004
  • Messages: 1254
  • Loc: Ro
  • Status: Offline

Message Septembre 4th, 2009, 6:55 am

Je vient de donner quelques conseils, pas le code exact pour les pouces multiples. Vient de faire bon usage de votre esprit et de le mettre ensemble. Im sûr que vous pouvez faire cela.
“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. ”

Afficher de l'information

  • Total des messages de ce sujet: 4 messages
  • Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 25 invités
  • Vous ne pouvez pas poster de nouveaux sujets
  • Vous ne pouvez pas répondre aux sujets
  • Vous ne pouvez pas éditer vos messages
  • Vous ne pouvez pas supprimer vos messages
  • Vous ne pouvez pas joindre des fichiers
 
 

© 2011 Unmelted, LLC. Ozzu® est une marque déposée de Unmelted, LLC