A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: When i Drag and Drop, how can i control a dragable movieclip is full inside target...

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    8

    When i Drag and Drop, how can i control a dragable movieclip is full inside target...

    When i use drag and drop, i have two movieclip. One of them is target, the other is draggable movieclip.
    When i drag the movieclip on to target, can i control the dragable movieclip is full inside of target. Because my movieclips are not regular shapes.
    When one of the movieclip come on the other movieclip, they must not cross each other. How can i control of this?

  2. #2
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Even if your movieclips are not regular shapes, you can make the "movieclip hotspot" of your desire. Let's suppose our moviclip is a start shaped one, you can create another movieclip inside of that one, and that will be our hotspot, and can have the shape you want, then when you give actions, you then call your hotspot movieclip and not your main movieclip. In my exaample, if i want to drag a movieclip on to my shaped star movieclip,not if the mouse is touching the star's peaks but when touching the center, then my hotspot movieclip will be a square, or a circle, positioned on the center of my start. That hotspot movieclip will be my main movieclip's boundaries. Maybe if you post your .fla, i can see better what you are trying to achieve.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    8
    First of all, thanks for your post. in my flash, there is 24 different shapes that are not regular, like differents clouds. I want to 6 shapes put on each other. But i drag and drop one shape to the other, i must control dragable shape is smaller than target shape. It must be full inside the target. And i have 6 shapes are above each other. And these shapes are changable. So i must control dragable shape is smaller than target shape. it must not cross each other. I think there is not a code for this. cross.png
    the .fla is here: www.demetkuyuk.com/izohipsler.fla

  4. #4
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    I don't really understand what you need. But this is something i think will help you. To detect the movieclips size, do this:

    PHP Code:
    on (press){      //movieclip1
        
    startDrag(thisfalse);
    }
    on (release){
    this.stopDrag();
    if (
    this.hitTest(_root.movieclip2) && this._height<=_root.movieclip2._height && this._width<=_root.movieclip2._width){
    //Do This
    }
    else if (
    this.hitTest(_root.movieclip2) && this._height>=_root.movieclip2._height && this._width>=_root.movieclip2._width){
    //Do this other thing
    }

    In that script, we are detecting If movieclip1 touches m ovieclip 2, and if the width and height of movieclip 1 is equal or smaller than movieclip's 2 height and width, Do this, but if movieclip1 touches m ovieclip 2, and if the width and height of movieclip 1 is equal or higher than movieclip's 2 height and width, Do this other thing.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    8
    Thank you very much, if my shapes is a circle or square, this code really works great. Bu my shapes aren't like a regular shape. Thay are like a cloud shape. So when i drag and drop a shape to the target, i want that all of the shape(movieclip1) is inside of the target(movieclip2). I want to control of this situation. shape(movieclip1) must not overflow from target(movieclip2).
    is it possible?

  6. #6
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Maybe try something like this...

    Code:
    import flash.display.BitmapData;
    import flash.geom.ColorTransform;
    import flash.geom.Matrix;
    import flash.geom.Rectangle;
    
    myDrag.onPress = function() {
            this.startDrag();
    };
    myDrag.onRelease = function() {
            stopDrag();
            trace(isContained(this, myTarget));
    };
    function isContained(p_clip1:MovieClip, p_clip2:MovieClip,
    p_alphaTolerance:Number):Boolean {
            // adapted from
    http://gskinner.com/blog/archives/2005/10/source_code_sha.html
            // note: clip1 must be able to fit inside clip2
            // set up default params:
            if (p_alphaTolerance == undefined) {
                    p_alphaTolerance = 255;
            }
            // get bounds:
            var bounds1:Object = p_clip1.getBounds(_root);
            var bounds2:Object = p_clip2.getBounds(_root);
            // rule out anything that we know can't collide:
            if (((bounds1.xMax < bounds2.xMin) || (bounds2.xMax < bounds1.xMin))
    || ((bounds1.yMax < bounds2.yMin) || (bounds2.yMax < bounds1.yMin))) {
                    return false;
            }
            // determine test area boundaries:
            var bounds:Object = {};
            bounds.xMin = Math.max(bounds1.xMin, bounds2.xMin);
            bounds.xMax = Math.min(bounds1.xMax, bounds2.xMax);
            bounds.yMin = Math.max(bounds1.yMin, bounds2.yMin);
            bounds.yMax = Math.min(bounds1.yMax, bounds2.yMax);
            // set up the image to use:
            var img:BitmapData = new BitmapData(bounds.xMax - bounds.xMin,
    bounds.yMax - bounds.yMin, false);
            // draw in the first image:
            var mat:Matrix = p_clip1.transform.concatenatedMatrix;
            mat.tx -= bounds.xMin;
            mat.ty -= bounds.yMin;
            img.draw(p_clip1,mat,new ColorTransform(1, 1, 1, 1, 255, -255, -255,
    p_alphaTolerance));
            // overlay the second image:
            mat = p_clip2.transform.concatenatedMatrix;
            mat.tx -= bounds.xMin;
            mat.ty -= bounds.yMin;
            img.draw(p_clip2,mat,new ColorTransform(1, 1, 1, 1, 255, 255, 255,
    p_alphaTolerance),"difference");
            // find the intersection:
            var intersection:Rectangle = img.getColorBoundsRect(0x00FFFFFF,
    0x00FF0000, true);
            // if there is no intersection, return true:
            if (intersection.width == 0) {
                    return true;
            }
            return false;
    }

  7. #7
    Junior Member
    Join Date
    Nov 2012
    Posts
    8

    It's really amazing...

    this is exactly what I want, thank you very much...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center