No Sound Playing - but is Tracing
I have this simple code on frame 1 of a brand new fla. There are no other layers and there is nothing on the stage. There is nothing in the library. The sound file is in the same folder as the sound file. I am getting no errors in the Output. The traces are working. I get:
[object Sound]
[object URLRequest]
But, the sound does not play!! What is going on here?
PHP Code:
var soundReq:URLRequest = new URLRequest("correct1.wav");
var sound:Sound = new Sound();
sound.load(soundReq);
sound.addEventListener(Event.COMPLETE, onComplete);
function onComplete(event:Event):void
{
trace(sound);
trace(soundReq);
sound.play();
}
Drag and Drop Game: Move coordinates and add sound to dropped items.
This is for a Drag/Drop Game. I am trying to move coordinates and add sound to dropped items.
Regarding the previous post, I got sound.fla to work by converting my audio file into an mp3 with Sound Forge. Then the sound actually played.
Now, for what's left:
1. The audio needs to play when the item is dropped on the correct target !! Can you help? Where should the sound code go?
2. When each item is dropped onto the correct target, it should be placed at a particular x and y coordinate, and not affect the coordinate of either of the other 2 items. I'm thinking the code should be logically like this, but I'm not sure if I am right and need help coding it? Am I right? Can you write the code for me?
I have 3 items and 3 targets. Each item can ONLY go with a certain target.
If the airplane (ap) hits the target AND the covered wagon(cw) has not dropped correctly, and the train(tn) has not dropped correctly, then place ap at certain coordinates, and leave the cw and tn at the starting coordinates on the stage.
If the ap dropped correctly, and the cw has dropped correctly and tn has NOT dropped correctly, place ap and cw in the new locations and tn should go back/stay at it's starting coordinate on the stage.
If the ap has dropped correctly, and the cw has not dropped correctly and tn has dropped correctly, place ap and tn in the new locations and cw should go back/stay at it's starting coordinate on the stage.
etc. Does this make sense?
I tried to code this before but got a funky outcome, of when I dragged the airplane to its correct target, that the airplane did move to its correct new coordinates, but the other 2 items got moved to the top left of the entire Flash movie....not even back to the starting coordinates.
Thanks in advance for your help.
Sound Code:
PHP Code:
var soundReq:URLRequest = new URLRequest("correct1.mp3");
var sound:Sound = new Sound();
sound.load(soundReq);
sound.addEventListener(Event.COMPLETE, onComplete);
function onComplete(event:Event):void
{
trace(sound);
trace(soundReq);
sound.play();
}
DragGame.as:
PHP Code:
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.display.DisplayObject;
import flash.media.Sound;
import flash.net.URLRequest;
import DragDrop;
import TN;
import AP;
import CW;
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
{
tn = new TN();
addChild(tn);
tn.x = 169.9;
tn.y = 90.8;
tn.width = 370.9;
tn.height = 68;
tn.alpha = 0.3;
ap = new AP();
addChild(ap);
ap.x = 496.6;
ap.y = 169.9;
ap.width = 162.8;
ap.height = 110.2;
ap.alpha = 0.3;
cw = new CW();
addChild(cw);
cw.x = 44.8;
cw.y = 193.1;
cw.width = 197.0;
cw.height = 94;
cw.alpha = 0.3;
}
public function setUpTargets():void
{
//tn._targetPiece = ttn_mc;
//tn.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
trace(ttn_mc);
//ap._targetPiece = tap_mc;
//ap.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
trace(tap_mc);
// cw._targetPiece = tcw_mc;
//cw.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
trace(tcw_mc);
apm._targetPiece = tap_mc;
apm.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
trace(tap_mc);
cwm._targetPiece = tcw_mc;
cwm.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
trace(tcw_mc);
tnm._targetPiece = ttn_mc;
tnm.addEventListener(MouseEvent.MOUSE_UP, checkTarget);
trace(ttn_mc);
}
public function checkTarget(event:MouseEvent):void
{
if(apm.hitTestObject(apm._targetPiece) /*&& (cwm.hitTestObject(cwm._targetPiece))! && (tnm.hitTestObject(tnm._targetPiece)))!*/)
{
trace("whooooot!");
//ec.x = target.x;
//ec.y = target.y;
apm.x = 497.6;
apm.y = 409.9;
//cwm.x = 200;
//cwm.y = 200;
//tnm.x = 181.9;
//tnm.y = 295.8;
apm.removeEventListener(MouseEvent.MOUSE_UP, checkTarget);
apm.disable();
}
else
{
apm.x = apm._origX;
apm.y = apm._origY;
}
/*if(cwm.hitTestObject(cwm._targetPiece))
{
trace("whooooot!");
// trace(correctsound);
// correctsound.play();
//ec.x = target.x;
//ec.y = target.y;
//apm.x = 497.6;
//apm.y = 409.9;
cwm.x = 50.3;
cwm.y = 426.1;
//tnm.x = 181.9;
//tnm.y = 295.8;
cwm.removeEventListener(MouseEvent.MOUSE_UP, checkTarget);
cwm.disable();
}
else
{
//wrongsound.play();
cwm.x = cw.x;
cwm.y =cw.y;
}
if(tnm.hitTestObject(tnm._targetPiece))
{
trace("whooooot!");
//trace(correctsound);
//correctsound.play();
//ec.x = target.x;
//ec.y = target.y;
//apm.x = 497.6;
//apm.y = 409.9;
//cwm.x = 50.3;
//cwm.y = 426.1;
tnm.x = 181.9;
tnm.y = 295.8;
tnm.removeEventListener(MouseEvent.MOUSE_UP, checkTarget);
tnm.disable();
}
else
{
// wrongsound.play();
tnm.x = tnm._origX;
tnm.y = tnm._origY;
}*/
}
}
}
Sound works! (testing locally)....But not on the Internet
Hi again,
So I got my code figured out and the sound is working exactly the way I want it to when I test movie from Flash CS3...but when I upload to the Internet the sound is not working, or so it seems. I have uploaded the swf file in an html file along with the 2 sounds that I use for the movie. When I do the part of the movie that is supposed to trigger the sound, it says that it is waiting for my server (Waiting for www.designsbydegrees.com). What could be causing this? Something in the publish settings perhaps?
Thanks,
~R