A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: target movieclip from document class

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    5

    target movieclip from document class

    hi
    i am making a drag drop game.
    i created a doc class for the dragged items .
    i want to make the hit test with some movie clips on the stage but inside the class they are not seen by there names.
    how to perform my hit test


    this is my code,and target1_mc &target2_mc are movie clips on the stage

    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(event.target.target1_mc)
    ||this.hitTestObject(event.target.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;
    }

    }
    }
    }




    can any one help???

  2. #2
    Senior Member
    Join Date
    Jul 2008
    Posts
    391
    What is RecipeMC? Is it the MovieClip you are trying to do the hitTest on target1_mc and target2_mc with?

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    5
    recipeMc is the class name of the object in the libraray which is called also the same name.

    and right it is the object i want to hit with

  4. #4
    Registered User
    Join Date
    Dec 2010
    Posts
    5
    i am sorry this is not document class ,it is the class of certain movieclip

  5. #5
    Senior Member
    Join Date
    Jul 2008
    Posts
    391
    If target1_mc and target2_mc are on the stage at runtime then the document class will be able to reference them. So in recipeMc you can do

    PHP Code:
    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;
    var 
    documentclass:*;////////////////////

    public function recipeMC() {
    this.mouseChildren false;
    this.buttonMode true;
    this.addEventListener(MouseEvent.MOUSE_DOWNpickUp);
    this.addEventListener(MouseEvent.MOUSE_UPdropIt);
    }
    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();
    documentclass this.parent;

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

    }
    }

    Doing event.target.target1_mc is wrong because event.target means the object that triggered the event. So the object that triggered this MOUSE_UP event is recipeMc, and target1_mc and target2_mc are not children of recipeMc.

  6. #6
    Registered User
    Join Date
    Dec 2010
    Posts
    5
    thanks for your help

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