Skip to main content
Participant
September 12, 2011
Question

A drag and drop game with dynamic text response

  • September 12, 2011
  • 2 replies
  • 1018 views

Hi,

I am a teacher and my school has recently upgraded to Adobe Design Premium.  Our previous version was about 5 versions out of date.

I teach A Level which requires students to create an Interactice Multimedia product.

In the previous 6 years, I have taught students how to create simple drag and drop game with dynamic text responses.

Since the upgrade to Actionscript 3.0 the dynamic text response has ceased working.

When creating the game from scratch, I need to move to Actionscript 2.0 as 3.0 does not allow me to add actionscript to objects - I know and am sure that this is a better way of doing things, but I would prefer to keep working the way I am used to.

I use a switch case statement which I have copied below to make the drag and drop work.  The objects I apply the code to work in that they can be dragged, however, my dynamic text box with a variable name of "answer" is no longer displaying the response when an answer is left on a dropzone (rectangle converted to a symbol and given an instance name).

on(press) {
startdrag(this);
}

on(release) {
stopdrag();
switch(this._droptarget) {
  case "/dropzoneB":
   _root.answer="Well done";
   break;
  case "/dropzoneA":
  case "/dropzoneC":
   _root.answer="Hopeless";
   break;
  default:
   _root.answer="";
   break;
}
}

Any help would be much apeciated.

Thanks

Adrian

This topic has been closed for replies.

2 replies

Ned Murphy
Legend
September 12, 2011

You should avoid using the 'variable' aspect of textfields.  Instead, always assign the textfield an instance name and assign the text to the text property of the textfield, as in tfieldname.text = "Hopeless";

If you are intending to use AS2, then you should post in the AS2 forum.

Inspiring
September 12, 2011

To drag in as3

blie_btn is the instance of the object drawin on the stage. In AS3 you have to assign a even listener, in this case MOUSE_DOWN, and MOUSE_UP, as we want the drag to stop if the mouse is not clicked. Then we fire the functions, and tell the object to start drag.

// Register mouse event functions
blue_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
blue_btn.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
 
red_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
red_btn.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
 
// Define a mouse down handler (user is dragging)
function mouseDownHandler(evt:MouseEvent):void {
     var object = evt.target;
     // we should limit dragging to the area inside the canvas
     object.startDrag();
}
 
function mouseUpHandler(evt:MouseEvent):void {
     var obj = evt.target;
          obj.stopDrag();
}

if you want to make the text do what you want then something like this might work.

In the function, you could add a text box onto the stage, give it a instance of something like outputText
and then:

outputText = ("Bla Bla Bla");

(^Not sure if this will work exactly^)
PS. I am currently a A-level student