Skip to main content
Participating Frequently
December 18, 2010
Answered

how to target movieclip on the stage from cutom class

  • December 18, 2010
  • 1 reply
  • 457 views

this is the code  and the movieclips are target1_mc & target2_mc

package {
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.text.TextField;


    public class recipeMC extends MovieClip {

        private var startX:Number;
        private var startY:Number;
        private var counter:Number=0;


        public function recipeMC() {
            this.mouseChildren = false;
            this.buttonMode = true;
            this.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
            this.addEventListener(MouseEvent.MOUSE_UP, dropIt);
        }
        private function pickUp(event:MouseEvent):void {
            this.startDrag(true);
            this.parent.addChild(this);
            startX = this.x;
            startY = this.y;

        }
        private function dropIt(event:MouseEvent):void {
            this.stopDrag();

            if (this.hitTestObject(target1_mc)
            ||this.hitTestObject(target2_mc) ) {
                this.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp);
                this.removeEventListener(MouseEvent.MOUSE_UP, dropIt);
                this.buttonMode = false;
                this.x = myTarget.x;
                this.y = myTarget.y;
                counter++;
            } else {
                //reply_txt.text = "Try Again!";
                this.x = startX;
                this.y = startY;
            }

        }
    }
}

This topic has been closed for replies.
Correct answer kglad

if target1_mc, for example, is on the main timeline (and that class instance is added to the display list), use:

MovieClip(root).target1_mc

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
December 18, 2010

if target1_mc, for example, is on the main timeline (and that class instance is added to the display list), use:

MovieClip(root).target1_mc