dcsimg
A Flash Developer Resource Site

Page 3 of 4 FirstFirst 1234 LastLast
Results 41 to 60 of 61

Thread: TypeError: Error #1009: Cannot access a property or method of a null object reference

  1. #41
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You should not redeclare the correctsound variable inside the function, or else that function will be using the local variable, which is not the same variable that will be referenced later. Lose the 'var' when setting it inside the function.

    Since checkTarget expects a MouseEvent, Flash tried to cast the event sent to it as that. But since the COMPLETE event is not a MouseEvent, you get that error.

    You don't want to call checkTarget on the sound load complete.

  2. #42
    Member
    Join Date
    Nov 2009
    Posts
    46
    I am pretty sure I don't fully understand how to implement your suggestion below:


    You can set a particular target point as a property on the objects and use that.

  3. #43
    Member
    Join Date
    Nov 2009
    Posts
    46
    I understand what you are saying. So should I create a new function that gets called when the sound is complete? And if so, how do i have it still only play when the target is dropped on the correct year?

    Quote Originally Posted by 5TonsOfFlax View Post
    You should not redeclare the correctsound variable inside the function, or else that function will be using the local variable, which is not the same variable that will be referenced later. Lose the 'var' when setting it inside the function.

    Since checkTarget expects a MouseEvent, Flash tried to cast the event sent to it as that. But since the COMPLETE event is not a MouseEvent, you get that error.

    You don't want to call checkTarget on the sound load complete.

  4. #44
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    All I meant by the target coordinates was that in the same sense you have _origX and _origY, you could have _targetX and _targetY. You sort of have that now, by using the _targetPiece's x and y.

    You partially answered your own question about checkTarget. Since you only want the sound to play when the target is dropped, you don't want the sound to play as soon as it loads. Leave the sound.play line in checkTarget. If you want to be sure that the sound is actually loaded before playing it, you could have a COMPLETE listener that sets a boolean variable, and check that before calling play. Or you could forget the COMPLETE listener, and just check whether correctsound.bytesLoaded == correctsound.bytesTotal.

  5. #45
    Member
    Join Date
    Nov 2009
    Posts
    46
    I think I understand what you are saying, but I am still having trouble with exactly what code to write and where....Could you please actually write out the code/fix my code below to do what I want it do? (I have only started learning AS3 about 4 days ago....so this is quite a learning experience for me.)

    PHP Code:
    package
    {
        
    import flash.display.MovieClip;
        
    import flash.events.MouseEvent;
        
    import flash.display.DisplayObject;
        
    import flash.media.Sound;
        
        
    import flash.net.URLRequest;
        
    import flash.events.Event;
        
        
    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;
            private var 
    correctsound:Sound;


            
            public function 
    DragGame()
            {
                
    createPieces();
                var 
    correctsoundReq:URLRequest = new URLRequest("correct1.wav");
               
    //var wrongsoundReq:URLRequest = new URLRequest ("audio/wrong1.wav");
               
    correctsound:Sound = new Sound();
               
    //var wrongsound:Sound = new Sound();
               
    correctsound.load(correctsoundReq);
               
    //wrongsound.load(wrongsoundReq);
               
    correctsound.addEventListener(Event.COMPLETE);
                
            }
            
            private function 
    createPieces():void
            
    {
                
                        

                
                
    tn = new TN();
                
    addChild(tn);
                
    tn.169.9;
                
    tn.90.8;
                
    tn.width 370.9;
                
    tn.height 68;
                
    tn.alpha 0.3;
                
                
                
    ap = new AP();
                
    addChild(ap);
                
    ap.496.6;
                
    ap.169.9;
                
    ap.width 162.8;
                
    ap.height 110.2;
                
    ap.alpha 0.3;
                
                
                
    cw = new CW();
                
    addChild(cw);
                
    cw.44.8;
                
    cw.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_UPcheckTarget);
               
               
    trace(ttn_mc);

               
    ap._targetPiece tap_mc;
               
    ap.addEventListener(MouseEvent.MOUSE_UPcheckTarget);
               
    trace(tap_mc);

               
    cw._targetPiece tcw_mc;
               
    cw.addEventListener(MouseEvent.MOUSE_UPcheckTarget);
               
    trace(tcw_mc);
               
               
    apm._targetPiece tap_mc;
               
    apm.addEventListener(MouseEvent.MOUSE_UPcheckTarget);
               
    trace(tap_mc);
               
               
    cwm._targetPiece tcw_mc;
               
    cwm.addEventListener(MouseEvent.MOUSE_UPcheckTarget);
               
    trace(tcw_mc);
               
               
    tnm._targetPiece ttn_mc;
               
    tnm.addEventListener(MouseEvent.MOUSE_UPcheckTarget);
               
    trace(ttn_mc);
               
            }
            
            
            
    /*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);
               
               
               if(
    ec.hitTestObject(target))
               {
                   
    trace("whooooot!");
                   
    correctsound.play();
                   
    ec.target.x;
                   
    ec.target.y;
                   
    apm.497.6;
                   
    apm.409.9;
                   
    cwm.50.3;
                   
    cwm.426.1;
                   
    tnm.181.9;
                   
    tnm.295.8;
                   
    ec.removeEventListener(MouseEvent.MOUSE_UPcheckTarget);
                   
    ec.disable();
               }
               else
               {
                   
    //wrongsound.play();
                   
    ec.ec._origX;
                   
    ec.ec._origY;
               }
           }
       }
        


  6. #46
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Since sound.play plays as soon as enough data has loaded, I'd recommend skipping the check altogether.
    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;
            private var 
    correctsound:Sound;


            
            public function 
    DragGame()
            {
                
    createPieces();
                var 
    correctsoundReq:URLRequest = new URLRequest("correct1.wav");
               
    //var wrongsoundReq:URLRequest = new URLRequest ("audio/wrong1.wav");
               
    correctsound:Sound = new Sound();
               
    //var wrongsound:Sound = new Sound();
               
    correctsound.load(correctsoundReq);
               
    //wrongsound.load(wrongsoundReq);
            
    }
            
            private function 
    createPieces():void
            
    {
                
    tn = new TN();
                
    addChild(tn);
                
    tn.169.9;
                
    tn.90.8;
                
    tn.width 370.9;
                
    tn.height 68;
                
    tn.alpha 0.3;
                
                
                
    ap = new AP();
                
    addChild(ap);
                
    ap.496.6;
                
    ap.169.9;
                
    ap.width 162.8;
                
    ap.height 110.2;
                
    ap.alpha 0.3;
                
                
                
    cw = new CW();
                
    addChild(cw);
                
    cw.44.8;
                
    cw.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_UPcheckTarget);
               
               
    trace(ttn_mc);

               
    ap._targetPiece tap_mc;
               
    ap.addEventListener(MouseEvent.MOUSE_UPcheckTarget);
               
    trace(tap_mc);

               
    cw._targetPiece tcw_mc;
               
    cw.addEventListener(MouseEvent.MOUSE_UPcheckTarget);
               
    trace(tcw_mc);
               
               
    apm._targetPiece tap_mc;
               
    apm.addEventListener(MouseEvent.MOUSE_UPcheckTarget);
               
    trace(tap_mc);
               
               
    cwm._targetPiece tcw_mc;
               
    cwm.addEventListener(MouseEvent.MOUSE_UPcheckTarget);
               
    trace(tcw_mc);
               
               
    tnm._targetPiece ttn_mc;
               
    tnm.addEventListener(MouseEvent.MOUSE_UPcheckTarget);
               
    trace(ttn_mc);
               
            }
            
            private function 
    checkTarget(event:MouseEvent):void
           
    {
               var 
    ec:MovieClip MovieClip(event.currentTarget);
               var 
    target:DisplayObject DisplayObject(ec._targetPiece);
               
               
               if(
    ec.hitTestObject(target))
               {
                   
    trace("whooooot!");
                   
    correctsound.play();
                   
    ec.target.x;
                   
    ec.target.y;
                   
    apm.497.6;
                   
    apm.409.9;
                   
    cwm.50.3;
                   
    cwm.426.1;
                   
    tnm.181.9;
                   
    tnm.295.8;
                   
    ec.removeEventListener(MouseEvent.MOUSE_UPcheckTarget);
                   
    ec.disable();
               }
               else
               {
                   
    //wrongsound.play();
                   
    ec.ec._origX;
                   
    ec.ec._origY;
               }
           }
       }
        

    I removed the import for Event as well, since it's no longer used as far as I can see.

  7. #47
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    In the IDE you can use Debug>Debug Movie (cmd+shift+enter) to get into the flash debugger - when you have an error you should be able to see the offending code there.
    Please use [php] or [code] tags, and mark your threads resolved 8)

  8. #48
    Member
    Join Date
    Nov 2009
    Posts
    46

    New errors

    I am now getting an error to the following line of code:

    correctsound:Sound = new Sound();

    1067: Implicit coercion of a value of type flash.media:Sound to an unrelated type Class.

    and

    1188: Illegal assignment to class Sound.

    How do I fix this?

  9. #49
    Member
    Join Date
    Nov 2009
    Posts
    46
    Can you fix my code to do this? I don't know how to do it.

    Quote Originally Posted by 5TonsOfFlax View Post
    All I meant by the target coordinates was that in the same sense you have _origX and _origY, you could have _targetX and _targetY. You sort of have that now, by using the _targetPiece's x and y.

  10. #50
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    That's what I get for copying your code and changing it instead of writing it over again, i guess.

    Remove the ":Sound" in the line where the error occurs.

  11. #51
    Member
    Join Date
    Nov 2009
    Posts
    46
    ok, so in the output window, I traced the correctsound variable and it is showing up as [object Sound]...but I don't hear anything !!

    Also, when I drag and drop 1 item correctly, ALL of the items are moved to their final locations, instead of just the one I am dragging !

  12. #52
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You are explicitly moving all of your clips when any of them are correct. It seems you need to associate the m versions with the non-m versions and only move the one that counts.

    This code is moving all your items:
    Code:
                   apm.x = 497.6;
                   apm.y = 409.9;
                   cwm.x = 50.3;
                   cwm.y = 426.1;
                   tnm.x = 181.9;
                   tnm.y = 295.8;

  13. #53
    Member
    Join Date
    Nov 2009
    Posts
    46
    I set up 3 if/else statements for each of the 3 modes of transportation, thinking this would be easier than to try to put it all in one argument. What do you think? It is not quite working so well.

    PHP Code:
    private function checkTarget(event:MouseEvent):void
           
    {
               var 
    ec:MovieClip MovieClip(event.currentTarget);
               var 
    target:DisplayObject DisplayObject(ec._targetPiece);
               
    trace(correctsound);
               
               if(
    ec.hitTestObject(apm._targetPiece))
               {
                   
    trace("whooooot!");
                   
    trace(correctsound);
                   
    correctsound.play();
                   
    //ec.x = target.x;
                   //ec.y = target.y;
                   
    apm.497.6;
                   
    apm.409.9;
                   
    //cwm.x = 50.3;
                   //cwm.y = 426.1;
                   //tnm.x = 181.9;
                   //tnm.y = 295.8;
                   
    ec.removeEventListener(MouseEvent.MOUSE_UPcheckTarget);
                   
    ec.disable();
               }
               else
               {
                   
    wrongsound.play();
                   
    apm.apm._origX;
                   
    apm.apm._origY;
               }
               
               if(
    ec.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.50.3;
                   
    cwm.426.1;
                   
    //tnm.x = 181.9;
                   //tnm.y = 295.8;
                   
    ec.removeEventListener(MouseEvent.MOUSE_UPcheckTarget);
                   
    ec.disable();
               }
               else
               {
                   
    wrongsound.play();
                   
    cwm.cwm._origX;
                   
    cwm.cwm._origY;
               }
               
               if(
    ec.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.181.9;
                   
    tnm.295.8;
                   
    ec.removeEventListener(MouseEvent.MOUSE_UPcheckTarget);
                   
    ec.disable();
               }
               else
               {
                   
    wrongsound.play();
                   
    tnm.ec._origX;
                   
    tnm.ec._origY;
               }
           } 

  14. #54
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Well, the core of the idea is solid, but this will always consider at least 2 of the 3 to be wrong. You need to 1. Not move one that's already marked correct as wrong. and 2. only consider things 'wrong' if NONE of the 3 matches.

  15. #55
    Member
    Join Date
    Nov 2009
    Posts
    46
    So I changed it to the following structure of : if , else if ,else if, else.

    Still not working quite right. The covered wagon (cwm) and the airplane (apm) work fine, but when I drop the train (tnm), it ALSO moves the airplane. Why?

    PHP Code:
            private function checkTarget(event:MouseEvent):void
           
    {
               var 
    ec:MovieClip MovieClip(event.currentTarget);
               
    //var target:DisplayObject = DisplayObject(ec._targetPiece);
               
    trace(correctsound);
               
               if(
    ec.hitTestObject(apm._targetPiece))
               {
                   
    trace("whooooot!");
                   
    trace(correctsound);
                   
    correctsound.play();
                   
    //ec.x = apm._targetPiece.x;
                   //ec.y = apm._targetPiece.y;
                   
    apm.497.6;
                   
    apm.409.9;
                   
    //cwm.x = 50.3;
                   //cwm.y = 426.1;
                   //tnm.x = 181.9;
                   //tnm.y = 295.8;
                   
    ec.removeEventListener(MouseEvent.MOUSE_UPcheckTarget);
                   
    ec.disable();
               }
               else if(
    ec.hitTestObject(cwm._targetPiece))
               {
                   
    trace("whooooot!");
                   
    trace(correctsound);
                   
    correctsound.play();
                   
    //ec.x = cwm._targetPiece.x;
                   //ec.y = cwm._targetPiece.y;
                   //apm.x = 497.6;
                   //apm.y = 409.9;
                   
    cwm.50.3;
                   
    cwm.426.1;
                   
    //tnm.x = 181.9;
                   //tnm.y = 295.8;
                   
    ec.removeEventListener(MouseEvent.MOUSE_UPcheckTarget);
                   
    ec.disable();
               }
               else if(
    ec.hitTestObject(tnm._targetPiece))
               {
                   
    trace("whooooot!");
                   
    trace(correctsound);
                   
    correctsound.play();
                   
    //ec.x = tnm._targetPiece.x;
                   //ec.y = tnm._targetPiece.y;
                   //apm.x = 497.6;
                   //apm.y = 409.9;
                   //cwm.x = 50.3;
                   //cwm.y = 426.1;
                   
    tnm.181.9;
                   
    tnm.295.8;
                   
    ec.removeEventListener(MouseEvent.MOUSE_UPcheckTarget);
                   
    ec.disable();
               }
               else
               {
                   
    wrongsound.play();
                   
    //ec.x = ec._origX;
                   //ec.y = ec._origY;
               


  16. #56
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I don't see why that would be. Incidentally, with that code, you should be able to drag any of your vehicles to any target. I'm pretty sure that's not what you wanted.

  17. #57
    Member
    Join Date
    Nov 2009
    Posts
    46

    Can't get sound to play!

    Hello Again,
    I am trying to get sound to play after I drag a graphic onto its correct target (a drag/drop game). I have 2 .as files. One called DragGame.as which is the document class, and another one called DragDrop.as. Both are below. I have tried adding the sound with and without a loader, and I have checked the sound in the same folder with my fla. When I don't use the loader, nothing happens - no sound. When I use the loader, I am just testing locally and getting the error: "Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error.
    ". I have also checked the spelling of the file. I have tried with and without the .wav extension. I have also tried a .mp3 file, with and without the extension. No matter what I have tried, it will not play. Please help!
    Thanks,
    ~rorose

    This is the 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;
            private var 
    correctsound:Sound;



            
            public function 
    DragGame()
            {
                
    createPieces();

            }
            
            private function 
    createPieces():void
            
    {
                

                        

                
                
    tn = new TN();
                
    addChild(tn);
                
    tn.169.9;
                
    tn.90.8;
                
    tn.width 370.9;
                
    tn.height 68;
                
    tn.alpha 0.3;
                
                
                
    ap = new AP();
                
    addChild(ap);
                
    ap.496.6;
                
    ap.169.9;
                
    ap.width 162.8;
                
    ap.height 110.2;
                
    ap.alpha 0.3;
                
                
                
    cw = new CW();
                
    addChild(cw);
                
    cw.44.8;
                
    cw.193.1;
                
    cw.width 197.0;
                
    cw.height 94;
                
    cw.alpha 0.3;
                
            }
            
            public function 
    setUpTargets():void
            
    {


                
               
    // trace(correctsound);
                
               //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_UPcheckTarget);
               
    trace(tap_mc);
               
               
    cwm._targetPiece tcw_mc;
               
    cwm.addEventListener(MouseEvent.MOUSE_UPcheckTarget);
               
    trace(tcw_mc);
               
               
    tnm._targetPiece ttn_mc;
               
    tnm.addEventListener(MouseEvent.MOUSE_UPcheckTarget);
               
    trace(ttn_mc);
               
            }
            

            
            public function 
    checkTarget(event:MouseEvent):void
           
    {

               
    correctsound = new Sound(new URLRequest("correct1.wav"));
              

                 
               if(
    apm.hitTestObject(apm._targetPiece/*&& (cwm.hitTestObject(cwm._targetPiece))! && (tnm.hitTestObject(tnm._targetPiece)))!*/)
               {
                   
    trace("whooooot!");
                   
    trace(correctsound);
                   
    correctsound.play();
                   
    //ec.x = target.x;
                   //ec.y = target.y;
                   
    apm.497.6;
                   
    apm.409.9;
                   
    //cwm.x = 200;
                   //cwm.y = 200;
                   //tnm.x = 181.9;
                   //tnm.y = 295.8;
                   
    apm.removeEventListener(MouseEvent.MOUSE_UPcheckTarget);
                   
    apm.disable();
               }
               else
               {
                  
                   
    apm.apm._origX;
                   
    apm.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;
               }*/
           
    }
       }
        

    This is the DragDrop.as:

    PHP Code:
    package
    {
        
    import flash.display.MovieClip;
        
    import flash.events.MouseEvent;
        
    import flash.filters.DropShadowFilter;
        
    import flash.display.DisplayObject;
            
    import flash.events.Event;
            
    import flash.media.Sound;
            
    import flash.net.URLRequest;
            
    import flash.media.SoundChannel;
        
        public class 
    DragDrop extends MovieClip
        
    {
            public var 
    _targetPiece:*;
            public var 
    _origX:Number;
            public var 
    _origY:Number;

            
            public function 
    DragDrop()
            {
                
    _origX this.x;
                
    _origY this.y;

                
    this.buttonMode true;
                
    this.addEventListener(MouseEvent.MOUSE_DOWN,dragMovie);
                
    this.addEventListener(MouseEvent.MOUSE_UPdropMovie);


                
            }
            
            private function 
    dragMovie(event:MouseEvent):void
            
    {
                
    this.startDrag();
                
    _origX event.target.x;
                
    _origY event.target.y;
                
    this.filters = [new DropShadowFilter()];
                
    this.parent.addChild(this);
                
            }
            
            private function 
    dropMovie(event:MouseEvent):void
            
    {
                
    this.stopDrag();
                
    this.filters = [];
                
    stopDrag();
                        
    trace(_targetPiece);
                        
    trace(dropTarget);
                if ((
    dropTarget != null) && (_targetPiece != null) && (_targetPiece.contains(dropTarget))){
                        
                           
    removeEventListener(MouseEvent.MOUSE_DOWNdragMovie);
                           
    removeEventListener(MouseEvent.MOUSE_UPdropMovie);
                           
    buttonMode false;
                           
    _targetPiece.x;
                           
    _targetPiece.y;
                 } else {
                           
    _origX;
                           
    _origY;
                 }
            }
            
            
            public function 
    disable():void
            
    {
                
    this.buttonMode false;
                
    this.removeEventListener(MouseEvent.MOUSE_DOWN,dragMovie);
                
    this.removeEventListener(MouseEvent.MOUSE_UPdropMovie);
            }
        }


  18. #58
    Member
    Join Date
    Nov 2009
    Posts
    46

    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.COMPLETEonComplete);

    function 
    onComplete(event:Event):void
    {
        
    trace(sound);
        
    trace(soundReq);
        
    sound.play();
        


  19. #59
    Member
    Join Date
    Nov 2009
    Posts
    46

    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.COMPLETEonComplete);

    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.169.9;
                
    tn.90.8;
                
    tn.width 370.9;
                
    tn.height 68;
                
    tn.alpha 0.3;
                
                
                
    ap = new AP();
                
    addChild(ap);
                
    ap.496.6;
                
    ap.169.9;
                
    ap.width 162.8;
                
    ap.height 110.2;
                
    ap.alpha 0.3;
                
                
                
    cw = new CW();
                
    addChild(cw);
                
    cw.44.8;
                
    cw.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_UPcheckTarget);
               
    trace(tap_mc);
               
               
    cwm._targetPiece tcw_mc;
               
    cwm.addEventListener(MouseEvent.MOUSE_UPcheckTarget);
               
    trace(tcw_mc);
               
               
    tnm._targetPiece ttn_mc;
               
    tnm.addEventListener(MouseEvent.MOUSE_UPcheckTarget);
               
    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.497.6;
                   
    apm.409.9;
                   
    //cwm.x = 200;
                   //cwm.y = 200;
                   //tnm.x = 181.9;
                   //tnm.y = 295.8;
                   
    apm.removeEventListener(MouseEvent.MOUSE_UPcheckTarget);
                   
    apm.disable();
               }
               else
               {
                  
                   
    apm.apm._origX;
                   
    apm.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;
               }*/
           
    }
       }
        


  20. #60
    Member
    Join Date
    Nov 2009
    Posts
    46

    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center