Skip to main content
Inspiring
August 16, 2009
Answered

hitTest and draggable MCs

  • August 16, 2009
  • 1 reply
  • 454 views

**These codes are in the draggable MC: fish1_drag

Hi, this is my code:

onClipEvent (enterFrame) {
    this.onPress = function() {
        startDrag(this);
    };

    _root.UI1_mc.UI1_mc2.inv_mc.ISpace1.onEnterFrame = function() {
        if (this.hitTest(fish1_drag)) {
            stopDrag();
        } else {
        }
    };
}

I keep jumbling it up so that one thing works but the other doesnt. But basicly I need it so that when I drag fish1_drag (instance name) over ISpace1 (which is within many MCs : _root.UI1_mc.UI1_mc2.inv_mc.ISpace1 but opens up so you can drag it over it) for it the drop on the ISpace1.

I have another MC in the library and il get that the attach to the ISpace1 but what im finding difficult is just being able to drag the fish1_drag over the ISpace1 and releasing.

Here is some other reandom code that I have in a comment on my AC panel:

/*

            this.onRelease = function() {
                stopDrag();
                _root.UI1_mc.UI1_mc2.inv_mc.ISpace1.attachMovie("fish1_mc","attached1",this.getNextHighestDepth());
                _root.invCount += 1;
                updateAfterEvent();  // I probly dont need this updateAfterEvent. but its there anyway.
            };

*/

Thanks please help, hope you understand my jibberish speech.

This topic has been closed for replies.
Correct answer kglad

the code i gave should be attached to the timeline that contains fish1_drag and your code should be removed.  in particular, there should be no code attached to a movieclip.

1 reply

kglad
Community Expert
Community Expert
August 16, 2009

use:




    fish1_drag.onPress = function() {
       this.startDrag();
    };

    _root.UI1_mc.UI1_mc2.inv_mc.ISpace1.onEnterFrame = function() {
        if (this.hitTest(fish1_drag)) {

delete this.onEnterFrame;
            stopDrag();
        }
    };

Inspiring
August 16, 2009

OK thanks but... as my timelines are a bit messy it probly isnt letting the code wrk properly but.. it now cant even drag.

onClipEvent (enterFrame) {
    fish1_drag.onPress = function() {
        this.startDrag();
    };
    _root.UI1_mc.UI1_mc2.inv_mc.ISpace1.onEnterFrame = function() {
        if (this.hitTest(fish1_drag)) {
            delete this.onEnterFrame;
            stopDrag();
        }
    };
}

doesnt even drag.

I tried it with fish1_drag being: this

and fish1_drag_mc

and I added a linkage of fish1_drag but nothing worked, its probly because the inventory is nested weirdly, il keep trying.

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
August 16, 2009

the code i gave should be attached to the timeline that contains fish1_drag and your code should be removed.  in particular, there should be no code attached to a movieclip.