0

Let's go straight to the question I want to do this in Adobe Animation and whit Action Script language,please help me write code

Rules of the game: Each colored circle will hit its color rectangle and the circle will disappear and the will be Change to Predefined rectangle and traced "warning" or do some action for other rectangle hit or black rectangles hit

Schematic image uploaded to better clarify what I want there is no problem if you change it all my code

Attention:I am a beginner, try with complete explanations

Challenges I have:

1- I don't know how to warn if the circle collides with irrelevant colors or black rectangles.

image

2- I want to warn at the moment of the collision, but the code I wrote delays, for example, the red circle disappears exactly when it hits the red rectangle (this is delayed in my code).

my fla code:
redCirc_mc.target = redRec_mc;
yelCirc_mc.target = yelRec_mc;
greenCirc_mc.target = greenRec_mc;

my class code:
package  {
    import flash.events.MouseEvent
    import flash.display.MovieClip
    import fl.transitions.Fade;


        public class DragDrop extends MovieClip {

            public var target:MovieClip;
            private var originalX:Number;
            private var originalY:Number;

            public function DragDrop(){

                originalX=this.x;
                originalY=this.y;
                this.addEventListener(MouseEvent.MOUSE_DOWN,drag);}

            private function drag(event:MouseEvent):void{
                this.startDrag();
                this.parent.addChild(this);
                this.addEventListener(MouseEvent.MOUSE_UP,drop);
                }

            private function drop(event:MouseEvent):void{
                this.stopDrag();
                this.removeEventListener(MouseEvent.MOUSE_UP,drop);


                if (this.hitTestObject(target)){
                    trace("hit!");
                    this.visible=false;
                    }

                else{
                    this.x=originalX;
                    this.y=originalY;

                    }
                }
        }
    }
Mustafa
  • 977
  • 3
  • 12
  • 25
  • There are too many questions at once and they are not as simple as they might seem. I advise to do it in a few small comprehendable steps. Step №1: learn why **hitTestObject** might fail you and return **true** while there's no actual collision occurs: https://pandaclaire.wordpress.com/2010/09/08/the-art-of-collision-detection-in-as3-hittestobject/ – Organis Mar 15 '20 at 16:47
  • Thank you very much for your time and attention/// Ask a question here or ask a question in a new context? And how do I start with such a question: How can I divide each circle into two events when it hits: 1. When it hits its own rectangle 2. When dealing with other rectangles – Mehdi Salehi Mar 15 '20 at 19:04
  • One step at a time, and now you are trying to jump too far ahead. First, create a suitable logic that detects a collision between two shapes. Literally, do it so that you can design two shapes in any combination and the said logic yields the only result of **true** or **false**, so that you could say: *yes, it is exactly how I want it*. P.S. Start with rectangles so you could go with **hitTestObject(...)** first. – Organis Mar 15 '20 at 19:34

0 Answers0