I ran it with that one line of code update and now it has gone back to not dropping at all, just snapping back on mouse up. Any other ideas? Also, how could I get you the line numbers you're asking for?
I think you should get the line numbers if you compile for debug rather than production. I don't know, I don't use the IDE.
I also thought that I might have gotten that contains line backwards. Try swapping which one is checking for containing the other. Also, trace out _targetPiece and dropTarget in that function.
You did change it the way I intended, but I forgot that contains is a method of DisplayObjectContainer, not DisplayObject. You could cast, but dropTarget is not guaranteed to actually be a DisplayObjectContainer. Of course, if it's not a container, it doesn't contain anything. What did the traces say before you swapped the contains?
Since you know the targets will be MovieClips, you could even do that. But DisplayObjectContainer or Sprite seems like the best choice. Doing that, realize that you cannot set the target to be a TextField or Shape or something. I'm really not sure of the relationship between the dropTarget and the _targetPiece you've set, which is why i wanted the traces. Move them up outside of the if so that we see them regardless of whether the condition is fulfilled.
Ok, so some success here! Thanks! So there are actually 2 instances of, for example, the airplane. The lighter one (lower alpha) that is being generated automatically by the addChild to the stage. When I click on that one and bring it to the target, I get the Whoooooot!!! Is it possible to make the instance of the airplane that is 100% alpha that I place on the stage manually in an earlier frame also react to the drop target? If so, how?
Basically, you need to get the original instances when you are setting the targets and checking stuff up, instead of the more transparent instances. If they have instancenames, you should be able to access them within the setUpTargets method.
Hi again,
I am trying to have a short sound play if the mode of transportation is dragged to the correct year. I have tried to add the code...but does not work. Could you please review it and let me know how the code should be?
Thanks!
public function setUpTargets():void
{
var correctsoundReq:URLRequest = new URLRequest("correct1.wav");
//var wrongsoundReq:URLRequest = new URLRequest ("audio/wrong1.wav");
var correctsound:Sound = new Sound();
//var wrongsound:Sound = new Sound();
correctsound.load(correctsoundReq);
//wrongsound.load(wrongsoundReq);
/*private function onComplete(event:Event):void
{
correctsound.play();
}*/
private function checkTarget(event:MouseEvent):void
{
var ec:MovieClip = MovieClip(event.currentTarget);
var target:DisplayObject = DisplayObject(ec._targetPiece);
You need to import Event like you did with MouseEvent.
You declared correctsound as a local variable in setUpTargets. That means that that variable has no meaning outside of that function. You should move the declaration up to the class level in order to use it in checkTarget.
Hi again,
So I added the "import flash.events.Event;" to the package. And I tried to move the var declarations in the package area and the public function DragGame area and the private function createPieces...and I couldn't get them to work...where exactly should they go? With the code as it is below, I am getting an error on line 119, the line in the checkTarget function that says, "correctsound.play();"
public class DragGame extends MovieClip
{
private var tn:TN;
private var ap:AP;
private var cw:CW;
public function DragGame()
{
createPieces();
}
private function createPieces():void
{
var correctsoundReq:URLRequest = new URLRequest("correct1.wav");
//var wrongsoundReq:URLRequest = new URLRequest ("audio/wrong1.wav");
var correctsound:Sound = new Sound();
//var wrongsound:Sound = new Sound();
correctsound.load(correctsoundReq);
//wrongsound.load(wrongsoundReq);
correctsound.addEventListener(Event.COMPLETE, checkTarget);
/*private function onComplete(event:Event):void
{
correctsound.play();
}*/
private function checkTarget(event:MouseEvent):void
{
var ec:MovieClip = MovieClip(event.currentTarget);
var target:DisplayObject = DisplayObject(ec._targetPiece);
Also, I'd like to specify particular x and y locations of where the final placement of the dropped object should go once it has hit the target. Can you help with code for that?
public class DragGame extends MovieClip
{
private var tn:TN;
private var ap:AP;
private var cw:CW;
private var correctsound:Sound;
public function DragGame()
{
createPieces();
}
private function createPieces():void
{
var correctsoundReq:URLRequest = new URLRequest("correct1.wav");
//var wrongsoundReq:URLRequest = new URLRequest ("audio/wrong1.wav");
correctsound = new Sound();
//var wrongsound:Sound = new Sound();
correctsound.load(correctsoundReq);
//wrongsound.load(wrongsoundReq);
correctsound.addEventListener(Event.COMPLETE, checkTarget);
/*private function onComplete(event:Event):void
{
correctsound.play();
}*/
private function checkTarget(event:MouseEvent):void
{
var ec:MovieClip = MovieClip(event.currentTarget);
var target:DisplayObject = DisplayObject(ec._targetPiece);
For moving the object after it has successfully been dropped, you'd want to change the x and y in the section where you have 'whoooot'. You can set a particular target point as a property on the objects and use that.
var correctsoundReq:URLRequest = new URLRequest("correct1.wav");
and
private var correctsound:Sound;
Now I am getting this error:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event@22d6eeb1 to flash.events.MouseEvent.
Where should this part of the code go:
PHP Code:
var correctsoundReq:URLRequest = new URLRequest("correct1.wav"); //var wrongsoundReq:URLRequest = new URLRequest ("audio/wrong1.wav"); var correctsound:Sound = new Sound(); //var wrongsound:Sound = new Sound(); correctsound.load(correctsoundReq); //wrongsound.load(wrongsoundReq); correctsound.addEventListener(Event.COMPLETE, checkTarget);
public class DragGame extends MovieClip
{
private var tn:TN;
private var ap:AP;
private var cw:CW;
private var correctsound:Sound;
public function DragGame()
{
createPieces();
}
private function createPieces():void
{
var correctsoundReq:URLRequest = new URLRequest("correct1.wav");
//var wrongsoundReq:URLRequest = new URLRequest ("audio/wrong1.wav");
var correctsound:Sound = new Sound();
//var wrongsound:Sound = new Sound();
correctsound.load(correctsoundReq);
//wrongsound.load(wrongsoundReq);
correctsound.addEventListener(Event.COMPLETE, checkTarget);
/*private function onComplete(event:Event):void
{
correctsound.play();
}*/
private function checkTarget(event:MouseEvent):void
{
var ec:MovieClip = MovieClip(event.currentTarget);
var target:DisplayObject = DisplayObject(ec._targetPiece);