Skip to main content
Inspiring
May 10, 2011
Answered

pass over question

  • May 10, 2011
  • 1 reply
  • 361 views

Hey folks,

So I have this program that if you drag an object (in this case "circle2") over a predefined place it'll changed into another object ("square"). So this works, but being ambitious or crazy I'd like to have it that if I pass over a second object it'll change into something else. Now my problem is that I've defined a region using an if/else statement. So I can't add a second one or nothing happens. Is it possible to change from the if statement region to if the object (circle2) passes over another another mc? So if the circle passes over target 1 it'll become a square, if it passes over target 2 it'll change into a triangle. Here's my code below, any help would be appreciated.

backbutton.addEventListener(MouseEvent.CLICK, backclick);

helpbutton.addEventListener(MouseEvent.CLICK, helpclick);

answerbutton.addEventListener(MouseEvent.CLICK, answerclick);

circle2.addEventListener(MouseEvent.MOUSE_DOWN, grabMe);

circle.addEventListener(MouseEvent.MOUSE_DOWN, grabMe);

import fl.transitions.Tween;

import fl.transitions.easing.*;

import fl.transitions.TweenEvent;

import flash.display.Sprite;

import flash.events.Event;

//import caurina.transitions.Tweener;

//import com.greensock.*;

import flash.media.Sound;

var me:Object;

function grabMe(e:MouseEvent):void{

me = e.currentTarget;

me.removeEventListener(MouseEvent.MOUSE_DOWN, grabMe);

me.startDrag();

addChild(e.currentTarget as DisplayObject);

stage.addEventListener(MouseEvent.MOUSE_MOVE, dragMe);

stage.addEventListener(MouseEvent.MOUSE_UP, dropMe);

}

function dropMe(e:MouseEvent):void {

stage.removeEventListener(MouseEvent.MOUSE_UP, dropMe);

stage.removeEventListener(MouseEvent.MOUSE_MOVE, dragMe);

me.stopDrag();

me.addEventListener(MouseEvent.MOUSE_DOWN, grabMe);

}

function dragMe(e:MouseEvent):void {

e.updateAfterEvent();

if( me.x >= 291 && me.x <= 633 && me.y >= 311 && me.y <= 690  )

{

  me.gotoAndStop("Square")

}

else

{

   me.gotoAndStop("Circle")

}

}

function backclick(event:MouseEvent):void{

//testmenu.visible=false;

}

function helpclick(event:MouseEvent):void{

}

function answerclick(event:MouseEvent):void{

}

This topic has been closed for replies.
Correct answer Ned Murphy

You can either string along a series if conditionals, as in...

if(in this area){

     // square

} else if(in this other area){

     // something else

} else {

     // circle

}

Or you can use the hitTestObject() method if you create those areas as movieclips...

if(me.hitTestObject(this_area_MC)){

     // square

} else if((me.hitTestObject(this_other_area_MC){

     // something else

} else {

     // circle

}

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
May 10, 2011

You can either string along a series if conditionals, as in...

if(in this area){

     // square

} else if(in this other area){

     // something else

} else {

     // circle

}

Or you can use the hitTestObject() method if you create those areas as movieclips...

if(me.hitTestObject(this_area_MC)){

     // square

} else if((me.hitTestObject(this_other_area_MC){

     // something else

} else {

     // circle

}

Inspiring
May 10, 2011

Hittest worked, much appreciated. You the man....