ActionScript 3.0 - When all objects are drop, move to next scene.
I want to make drag and drop at certain coordinate.
I have two moving blocks, where player can drag any block at first time onto holder 1. Then, drag another block at second time onto holder 2.
When the block did not hits either holder 1 or holder 2, it will terminate and that block back to the initial coordinate.
When both hit both coordinate of holder, then move to next scene.
import flash.events.Event;
stop();//stop the scene
var startingPt:Point = new Point();//declaration variable
var movingBlock:Sprite;
var placed:int = 0;//initialize
var blok1:Boolean=false;
var blok2:Boolean=false;
var endpoint:Boolean=false;
block3.addEventListener(MouseEvent.MOUSE_DOWN, startBlockMove);//function
block2.addEventListener(MouseEvent.MOUSE_DOWN, startBlockMove);
function startBlockMove(evt:MouseEvent):void {//the object move
movingBlock = Sprite(evt.currentTarget);
startingPt.x = movingBlock.x;
startingPt.y = movingBlock.y;
stage.addEventListener(MouseEvent.MOUSE_MOVE, moveBlock);
}
function moveBlock(e:MouseEvent):void {//object move based on mouse coordinate
movingBlock.x = stage.mouseX;
movingBlock.y = stage.mouseY;
}
stage.addEventListener(MouseEvent.MOUSE_UP, stopMotion);//stop move
function stopMotion(evt:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_MOVE, moveBlock);
snapInPlace();
movingBlock = new Sprite();
startingPt = new Point();
}
function snapInPlace():void {//
if(blok1==false || blok2==false){
if (holder.hitTestObject(movingBlock)) {//object1 hits the goal
movingBlock.x = holder.x;
movingBlock.y = holder.y ;
placed++;
movingBlock.removeEventListener(MouseEvent.MOUSE_DOWN, startBlockMove);
blok1=true;
}
else if (holder1.hitTestObject(movingBlock)) {//object2 hits the goal
movingBlock.x = holder1.x;
movingBlock.y = holder1.y;
movingBlock.removeEventListener(MouseEvent.MOUSE_DOWN, startBlockMove);
blok2=true;
}
else {
movingBlock.x = startingPt.x;//if not hits the goal, return to original coordinate
movingBlock.y = startingPt.y;
blok1=false;
blok2=false;
}
}
else if(blok1==true && blok2==true){
setTimeout (function (){ endpoint=true;
trace("You died!");
removeEventListener(Event.REMOVED, snapInPlace);
gotoAndStop(1,"Scene 2");}, 1000);
}
}
The output gives error,
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at Untitled_2_fla::MainTimeline/snapInPlace()[Untitled_2_fla.MainTimeline::frame2:38]
at Untitled_2_fla::MainTimeline/stopMotion()[Untitled_2_fla.MainTimeline::frame2:31]
Where at frame2:38
if (holder.hitTestObject(movingBlock)) {}
and at frame2:31
snapInPlace();
How to solve this?
