Copy link to clipboard
Copied
Hi there! I'm a newbie flash user and working on a simulation for a graduate course in instructional design. I'm using Flash Professional CC on Mac. Here's what I'm trying to do. I have several draggable sprites on the stage and three target sprites. I have specified the original x,y locations of the sprites and have set the end x,y locations as those of each of the three targets. Items must be dragged to one of the three targets.
Some questions:
1. Can I specify more than one End x,y location for a draggable sprite? I'm creating a lesson to teach kindergartners how to sort lunchroom waste. If they have a napkin, for example, it could either go into the compost OR into the recycling. In cases like this where an item could really be placed into more than one bin, I want them to get it right if they do either of those things, rather than forcing them to choose which one.
2. To make my project more "fun" for kids, I wanted to customize the cursor with a graphic of hand. When I tried this in the flash file it works perfectly until I add the drag and drop functionality for the wasted items. Then the cursor will more around but not pick up any items. Once I revert back to the standard pointer, the correct drag and drop functionality is restored.
3. I have it set to snap back to the original location if learner attempts to drop the item on the wrong target. I want to be able to play a sound file when that happens, as well as play a sound file when it lands on the correct target, as well as shrink the item and change its opacity so that it appears invisible. I want to give the illusion of it being placed into the bin. I have no idea as to the proper way to code these events so that they happen.
4. I've watched dozens of hours of youtube tutorials before coming here. I'm a quick study, but am very new to action script. In one of the videos the developer showed referencing an external action script file which I don't think is an option in CC. The coding method he used seemed much more streamlined and "clean" than the chunks I'm working with now. Is there an easy way for me to code information about these objects than the way I've got it here now? I hate starting new things with bad habits. The perils of self-teaching.
Thanks!
I'm pasting my code from the actions panel below so you can see what's going on:
stop();
/* Custom Mouse Cursor
Replaces the default mouse cursor with the specified symbol instance.
*/
stage.addChild(customcursor);
customcursor.mouseEnabled = false;
customcursor.addEventListener(Event.ENTER_FRAME, fl_CustomMouseCursor);
function fl_CustomMouseCursor(event:Event)
{
customcursor.x = stage.mouseX;
customcursor.y = stage.mouseY;
}
Mouse.hide();
//To restore the default mouse pointer, uncomment the following lines:
customcursor.removeEventListener(Event.ENTER_FRAME, fl_CustomMouseCursor);
stage.removeChild(customcursor);
Mouse.show();
//set up variables and objects for dragging
var offset:int = 10;
var appleStartX:int = 243;
var appleStartY:int = 156;
var appleEndX:int = 522;
var appleEndY:int = 22;
apple.buttonMode = true;
apple.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
apple.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
var cupStartX:int = 39;
var cupStartY:int = 266;
var cupEndX:int = 520;
var cupEndY:int = 175;
cup.buttonMode = true;
cup.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
cup.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
var barStartX:int = 178;
var barStartY:int = 234;
var barEndX:int = 522;
var barEndY:int = 22;
bar.buttonMode = true;
bar.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
bar.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
var orangeStartX:int = 284;
var orangeStartY:int = 102;
var orangeEndX:int = 522;
var orangeEndY:int = 22;
orange.buttonMode = true;
orange.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
orange.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
var bottleStartX:int = 172;
var bottleStartY:int = 303;
var bottleEndX:int = 520;
var bottleEndY:int = 175;
bottle.buttonMode = true;
bottle.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
bottle.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
var bananaStartX:int = 113;
var bananaStartY:int = 123;
var bananaEndX:int = 522;
var bananaEndY:int = 22;
banana.buttonMode = true;
banana.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
banana.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
var napkinStartX:int = 248;
var napkinStartY:int = 271;
var napkinEndX:int = 520;
var napkinEndY:int = 175;
napkin.buttonMode = true;
napkin.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
napkin.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
var yogurtStartX:int = 27;
var yogurtStartY:int = 136;
var yogurtEndX:int = 518;
var yogurtEndY:int = 329;
yogurt.buttonMode = true;
yogurt.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
yogurt.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
var strawberryStartX:int = 120;
var strawberryStartY:int = 285;
var strawberryEndX:int = 522;
var strawberryEndY:int = 22;
strawberry.buttonMode = true;
strawberry.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
strawberry.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
var sandwichStartX:int = 7;
var sandwichStartY:int = 364;
var sandwichEndX:int = 522;
var sandwichEndY:int = 22;
sandwich.buttonMode = true;
sandwich.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
sandwich.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
var juiceStartX:int = 88;
var juiceStartY:int = 347;
var juiceEndX:int = 518;
var juiceEndY:int = 329;
juice.buttonMode = true;
juice.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
juice.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
var foilStartX:int = 39;
var foilStartY:int = 416;
var foilEndX:int = 520;
var foilEndY:int = 175;
foil.buttonMode = true;
foil.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
foil.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
var waxbagStartX:int = 235;
var waxbagStartY:int = 342;
var waxbagEndX:int = 522;
var waxbagEndY:int = 22;
waxbag.buttonMode = true;
waxbag.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
waxbag.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
function startDragging (e:MouseEvent) {
e.currentTarget.startDrag();
}
function stopDragging (e:MouseEvent) {
e.currentTarget.stopDrag();
switch (e.currentTarget) {
case apple:
if (apple.x < appleEndX - offset || apple.x > appleEndX + offset || apple.y < appleEndY - offset || apple.y > appleEndY + offset) {
apple.x = appleStartX;
apple.y = appleStartY;
}
else {
apple.x = appleEndX;
apple.y = appleEndY;
//checkGame();
}
break;
case sandwich:
if (sandwich.x < sandwichEndX - offset || sandwich.x > sandwichEndX + offset || sandwich.y < sandwichEndY - offset || sandwich.y > sandwichEndY + offset) {
sandwich.x = sandwichStartX;
sandwich.y = sandwichStartY;
}
else {
sandwich.x = sandwichEndX;
sandwich.y = sandwichEndY;
//checkGame();
}
break;
case orange:
if (orange.x < orangeEndX - offset || orange.x > orangeEndX + offset || orange.y < orangeEndY - offset || orange.y > orangeEndY + offset) {
orange.x = orangeStartX;
orange.y = orangeStartY;
}
else {
orange.x = orangeEndX;
orange.y = orangeEndY;
//checkGame();
}
break;
case strawberry:
if (strawberry.x < strawberryEndX - offset || strawberry.x > strawberryEndX + offset || strawberry.y < strawberryEndY - offset || strawberry.y > strawberryEndY + offset) {
strawberry.x = strawberryStartX;
strawberry.y = strawberryStartY;
}
else {
strawberry.x = strawberryEndX;
strawberry.y = strawberryEndY;
//checkGame();
}
break;
case napkin:
if (napkin.x < napkinEndX - offset || napkin.x > napkinEndX + offset || napkin.y < napkinEndY - offset || napkin.y > napkinEndY + offset) {
napkin.x = napkinStartX;
napkin.y = napkinStartY;
}
else {
napkin.x = napkinEndX;
napkin.y = napkinEndY;
//checkGame();
}
break;
case bar:
if (bar.x < barEndX - offset || bar.x > barEndX + offset || bar.y < barEndY - offset || bar.y > barEndY + offset) {
bar.x = barStartX;
bar.y = barStartY;
}
else {
bar.x = barEndX;
bar.y = barEndY;
//checkGame();
}
break;
case juice:
if (juice.x < juiceEndX - offset || juice.x > juiceEndX + offset || juice.y < juiceEndY - offset || juice.y > juiceEndY + offset) {
juice.x = juiceStartX;
juice.y = juiceStartY;
}
else {
juice.x = juiceEndX;
juice.y = juiceEndY;
//checkGame();
}
break;
case foil:
if (foil.x < foilEndX - offset || foil.x > foilEndX + offset || foil.y < foilEndY - offset || foil.y > foilEndY + offset) {
foil.x = foilStartX;
foil.y = foilStartY;
}
else {
foil.x = foilEndX;
foil.y = foilEndY;
//checkGame();
}
break;
case banana:
if (banana.x < bananaEndX - offset || banana.x > bananaEndX + offset || banana.y < bananaEndY - offset || banana.y > bananaEndY + offset) {
banana.x = bananaStartX;
banana.y = bananaStartY;
}
else {
banana.x = bananaEndX;
banana.y = bananaEndY;
//checkGame();
}
break;
case bottle:
if (bottle.x < bottleEndX - offset || bottle.x > bottleEndX + offset || bottle.y < bottleEndY - offset || bottle.y > bottleEndY + offset) {
bottle.x = bottleStartX;
bottle.y = bottleStartY;
}
else {
bottle.x = bottleEndX;
bottle.y = bottleEndY;
//checkGame();
}
break;
case waxbag:
if (waxbag.x < waxbagEndX - offset || waxbag.x > waxbagEndX + offset || waxbag.y < waxbagEndY - offset || waxbag.y > waxbagEndY + offset) {
waxbag.x = waxbagStartX;
waxbag.y = waxbagStartY;
}
else {
waxbag.x = waxbagEndX;
waxbag.y = waxbagEndY;
//checkGame();
}
break;
case cup:
if (cup.x < cupEndX - offset || cup.x > cupEndX + offset || cup.y < cupEndY - offset || cup.y > cupEndY + offset) {
cup.x = cupStartX;
cup.y = cupStartY;
}
else {
cup.x = cupEndX;
cup.y = cupEndY;
//checkGame();
}
break;
case yogurt:
if (yogurt.x < yogurtEndX - offset || yogurt.x > yogurtEndX + offset || yogurt.y < yogurtEndY - offset || yogurt.y > yogurtEndY + offset) {
yogurt.x = yogurtStartX;
yogurt.y = yogurtStartY;
}
else {
waxbag.x = waxbagEndX;
waxbag.y = waxbagEndY;
//checkGame();
}
}
}
Copy link to clipboard
Copied
Some questions:
1. Can I specify more than one End x,y location for a draggable sprite?
yes, use an if-else statement
I'm creating a lesson to teach kindergartners how to sort lunchroom waste. If they have a napkin, for example, it could either go into the compost OR into the recycling. In cases like this where an item could really be placed into more than one bin, I want them to get it right if they do either of those things, rather than forcing them to choose which one.
2. To make my project more "fun" for kids, I wanted to customize the cursor with a graphic of hand. When I tried this in the flash file it works perfectly until I add the drag and drop functionality for the wasted items. Then the cursor will more around but not pick up any items. Once I revert back to the standard pointer, the correct drag and drop functionality is restored.
assign your cursor's mouseEnabled property to false:
yourcursor.mouseEnabled=false;
3. I have it set to snap back to the original location if learner attempts to drop the item on the wrong target. I want to be able to play a sound file when that happens, as well as play a sound file when it lands on the correct target, as well as shrink the item and change its opacity so that it appears invisible. I want to give the illusion of it being placed into the bin. I have no idea as to the proper way to code these events so that they happen.
use the sound class to create a sound:
// initialize your correct sound once with
var correctSound:Sound=new CorrectSound(); // add an mp3 sound to your library and assign it class = CorrectSound
// apply the play() method everytime you want your sound to play:
correctSound.play();
// change an object's opacity:
someobject.alpha = .3; // partially visible
someobject.alpha = 1; // fully visible
someobject.visible=false; // not visible, at all.
// change an object's scale
someobject.scaleX=someobject.scaleY=.5; // shink width and height by 2
someobject.scaleX=someobject.scaleY=1; // resize to original
4. I've watched dozens of hours of youtube tutorials before coming here. I'm a quick study, but am very new to action script. In one of the videos the developer showed referencing an external action script file which I don't think is an option in CC. The coding method he used seemed much more streamlined and "clean" than the chunks I'm working with now. Is there an easy way for me to code information about these objects than the way I've got it here now? I hate starting new things with bad habits. The perils of self-teaching.
you could google:
actionscript 3 class coding
actionscript 3 object oriented programming
p.s. you can simplify and streamline your coding by learning about arrays and using hitTestObject.
Copy link to clipboard
Copied
Thank you!! I really appreciate you suggestion things for me to google as I definitely want to learn how to do this the right way. I'll check out those suggestions first and then dive back in to see what I can make of this mess. Thanks!
Mary
Copy link to clipboard
Copied
you're welcome.
(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now