Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Reset button for drag and drop?

New Here ,
Jun 17, 2009 Jun 17, 2009

I've designed a drag and drop game and I would like to add a button that resets both the draggable objects and the counter so that the game starts fresh and can be replayed.

Also, I would like the button to appear after all the draggable objects have been placed on their corresponding targets. Thanks in advance for your help!

Here's a link to the FLA:

http://www.stewart-mccoy.info/files/hazmat_dragdrop.fla

Below is the AS2 scripting:

// Drag and Drop
// Original by Alex Fish. Modified by Stewart McCoy.

var allCorrect = 0;
var reply = "Begin by dragging each placard to its target classification on the rear of the truck.";
// check if all answers
// are correct
this.onEnterFrame= function(){
    if(this.allCorrect==4){
        this.reply = "Congrats, you're on your way to becoming a HAZMAT expert! Click the next button to continue.";
    }
}

not_set_yet.onRelease = function() {
   
}

//====== variables ========

var fixedX:Number = compressed._x;
var fixedY:Number = compressed._y;
var fixedX2:Number = flammable._x;
var fixedY2:Number = flammable._y;
var fixedX3:Number = oxidizers._x;
var fixedY3:Number = oxidizers._y;
var fixedX4:Number = corrosive._x;
var fixedY4:Number = corrosive._y;

//======== end variables ========

//======== drag and drop functionality =========

//-------- begin compressed --------------
compressed.onPress = function() {
    startDrag(this);
    this._parent.reply.txt="";
};

compressed.onRelease = function() {
    if(compressed.hitTest(targetcompressed)){
        compressed._x = targetcompressed._x;
        compressed._y = targetcompressed._y;
        feedback.text = "That's correct. Now finish placing the remaining placards.";
        this._parent.allCorrect +=1;
    } else {
        compressed._x = fixedX;
        compressed._y = fixedY;
        feedback.text = "Try again!";
    }
    stopDrag();
};

//-------- end compressed ------------------------

//-------- begin flammable ----------------------

flammable.onPress = function() {
    startDrag(this);
    this._parent.reply.txt="";
};

flammable.onRelease = function() {
    if(flammable.hitTest(targetflammable)){
        flammable._x = targetflammable._x;
        flammable._y = targetflammable._y;
        feedback.text = "That's correct. Now finish placing the remaining placards.";
        this._parent.allCorrect +=1;
    } else {
        flammable._x = fixedX2;
        flammable._y = fixedY2;
        feedback.text = "Try again!";
    }
    stopDrag();
};

//-------- end flammable ------------------------

//-------- begin oxidizers ----------------------

oxidizers.onPress = function() {
    startDrag(this);
    this._parent.reply.txt="";
};

oxidizers.onRelease = function() {
    if(oxidizers.hitTest(targetoxidizers)){
        oxidizers._x = targetoxidizers._x;
        oxidizers._y = targetoxidizers._y;
        feedback.text = "That's correct. Now finish placing the remaining placards.";
        this._parent.allCorrect +=1;
    } else {
        oxidizers._x = fixedX3;
        oxidizers._y = fixedY3;
        feedback.text = "Try again!";
    }
    stopDrag();
};

//-------- end oxidizers ------------------------

//-------- begin corrosive ----------------------

corrosive.onPress = function() {
    startDrag(this);
    this._parent.reply.txt="";
};

corrosive.onRelease = function() {
    if(corrosive.hitTest(targetcorrosive)){
        corrosive._x = targetcorrosive._x;
        corrosive._y = targetcorrosive._y;
        feedback.text = "That's correct. Now finish placing the remaining placards.";
        this._parent.allCorrect +=1;
    } else {
        corrosive._x = fixedX4;
        corrosive._y = fixedY4;
        feedback.text = "Try again!";
    }
    stopDrag();
};

//-------- end corrosive ------------------------

//-------- Bring to Front Behavior --------------

mx.behaviors.DepthControl.bringToFront(compressed);
mx.behaviors.DepthControl.bringToFront(flammable);
mx.behaviors.DepthControl.bringToFront(oxidizers);
mx.behaviors.DepthControl.bringToFront(corrosive);

//-------- End behavior -------------------------

//========= end drag and drop  ========

TOPICS
ActionScript
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 17, 2009 Jun 17, 2009

I found that this code works to create a reset button:

//reset button
reset_btn.onRelease = function() {
    loadMovieNum("myfilename.SWF", 0);
}

I still haven't figured out how to hide the button and then make it appear after all the objects have been dropped on their targets.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 17, 2009 Jun 17, 2009

There are a variety of ways to hide something.  For a button it's best to just set its _visible property to false at the start and when the time comes to make it appear set reset_btn._visible = true.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 17, 2009 Jun 17, 2009
LATEST

Thanks for the heads up on how to deal with visibility.

Also, loadMovie ended up not working. It only functions in Flash Player. When I embed the SWF in PowerPoint or publish it with Presenter, loadMovie just fails to load the SWF indicated by the URL parameter. Any thoughts?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines