Saturday, December 31, 2005

Flash Player above 7: Tutor of SnapObject Actionscript in flash using HitTest

Create a Box Button. Again Convert this button to MovieClip.
Name the instance of the each MovieClip like source_mc
Create one more MovieClip in the Stage name the instance dest_mc

Select the button to write the actionscript by, RightClicking the source_mc MovieClip > 'Edit in place', select the button press F9.

Add the code:

  1. on (press, dragOver) {
  2. startDrag(this);
  3. //trace(this._name);
  4. }
  5. on (release, dragOut) {
  6. stopDrag();
  7. if (this.hitTest(_parent.dest_mc)) {
  8. trace("you hit the Destination");
  9. //trace(_parent.dest_mc._x);
  10. this._x = _parent.dest_mc._x;
  11. this._y = _parent.dest_mc._y;
  12. } //end-if
  13. }

    Here we are moving the position of the source_mc MovieClip to dest_mc MovieClip when the Movieclip finishing the moving by using HitTest
    Note: You can use _root or _parent that depends upon the place where we are using ,here using _parent.dest_mc.

No comments:

Adobe News