A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Strange sound error

  1. #1
    Member
    Join Date
    Jun 2011
    Posts
    85

    Unhappy Strange sound error

    Hi,

    sometimes I get this strange error during gameplay:

    Code:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    	at com.efg.framework_mod::SoundManager/playSound()[/Users/xxx/Documents/Developer/AS3_Flex/game_development/projects/xxx/SpaceGame/libs/src/com/efg/framework_mod/SoundManager.as:106]
    	at com.xxx.games.spacegame::Main/soundEventListener()[/Users/xxx/Documents/Developer/AS3_Flex/game_development/projects/xxx/SpaceGame/src/com/xxx/games/spacegame/Main.as:1407]
    	at flash.events::EventDispatcher/dispatchEventFunction()
    	at flash.events::EventDispatcher/dispatchEvent()
    	at com.xxx.games.spacegame::SpaceGame/createEnemyProj()[/Users/xxx/Documents/Developer/AS3_Flex/game_development/projects/xxx/SpaceGame/src/com/xxx/games/spacegame/SpaceGame.as:3708]

    I still don't know what causes the error. The only thing I discovered is that sometimes an object is null inside of my SoundManager. But I don't know why. I already checked all appropriate arrays if something's missing there but all seems to be ok there. This is an extremely nasty bug which lasts for several weeks now. Please - I need your help to get rid of this error in order to finish my game. Thank you very much.

    This is the part of the SoundManager where the error occurs:
    Code:
    	public function playSound(soundName:String, isSoundTrack:Boolean = false, loops:int = 1, offset:Number = 0, _volume:Number = 1, fadeIn:Boolean = false,
    									_duration:Number = 1):void {
    			
    		
    			
    		tempSoundTransform.volume = _volume;
    		
    			
    		tempSound = sounds[soundName];//sometimes null (still don't know why)
    			
    		if (!fadeIn) {
    			if (isSoundTrack) {
    				if (soundTrackChannel != null) {
    					soundTrackChannel.stop();
    				}
    				soundTrackChannel = tempSound.play(offset, loops);								
    				soundTrackChannel.soundTransform = tempSoundTransform;	
    			} else {
    				
    					
    				soundChannels[soundName] = tempSound.play(offset, loops);//sometimes null but still don't know why
    			
    				soundChannels[soundName].soundTransform = tempSoundTransform;//line 106 (see errors above)
    					
    							
    			}
    		} else {
    				
    			fadeInSoundTransform = new SoundTransform(0, 0);
    			
    			if (isSoundTrack) {
    				if (soundTrackChannel != null) {
    					soundTrackChannel.stop();
    				}
    				soundTrackChannel = tempSound.play(offset, loops, fadeInSoundTransform);
    			} else {
    				soundChannels[soundName] = tempSound.play(offset, loops, fadeInSoundTransform);
    				
    			}
    				
    			TweenLite.to(fadeInSoundTransform, _duration, {volume:_volume, onUpdate:updateFadeIn, onUpdateParams:[soundName, isSoundTrack]});
    		}
    	}
    this is line 3708 (see errors above):
    Code:
    dispatchEvent(new CustomEventSound(CustomEventSound.PLAY_SOUND, enemyProjSounds[tempEnemyProj._type], false, 0, 8, setSoundVolume, false, false, 0));
    This is the class CustomEventSound:
    Code:
    public function CustomEventSound(type:String, name:String, isSoundTrack:Boolean = false, loops:int = 0,
    				offset:Number = 0, _volume:Number = 1, fadeIn:Boolean = false, fadeOut:Boolean = false,
    			_duration:Number = 2, startVol:Number = 1, bubbles:Boolean = false, cancelable:Boolean = false)
    	{
    		super(type, bubbles, cancelable);
    		this.name = name;
    		this.loops = loops;
    		this.offset = offset;
    		this._volume = _volume;
    		this.isSoundTrack = isSoundTrack;
    		this.fadeIn = fadeIn;
    		this.fadeOut = fadeOut;
    		this._duration = _duration;
    		this.startVol = startVol;
    			
    	}
    		
    	public override function clone():Event {
    		return new CustomEventSound(type, name, isSoundTrack, loops, offset, _volume, fadeIn, fadeOut, _duration, startVol, bubbles, cancelable)
    	}
    		
    		
    	public override function toString():String {
    		return formatToString(type, "type", "bubbles", "cancelable", "eventPhase", name, isSoundTrack, loops, offset, _volume, fadeIn,
    					fadeOut, _duration, startVol);
    	}
    The Listener-function for CustomEventSounds-Events
    Code:
    override public function soundEventListener(e:CustomEventSound):void {
    			
    	if (e.type == CustomEventSound.PLAY_SOUND) {
    			
    	soundManager.playSound(e.name, e.isSoundTrack, e.loops, e.offset, e._volume, e.fadeIn, e._duration);
    	} else {
    		soundManager.stopSound(e.name, e.isSoundTrack, e.fadeOut, e._duration, e.startVol);
    	}
    }
    Last edited by drpelz; 04-18-2012 at 06:59 PM.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Line 106 in SoundManager is the immediate cause of the error, not line 3708 of SpaceGame. Stack traces show you the immediate cause, then the thing that called that function, then the thing that called that, etc. So the actual error is on line 106 in SoundManager. That's somewhere in playSound, but I don't know where. Which line is it?
    From your comments, it's probably this one:
    Code:
    soundTrackChannel = tempSound.play(offset, loops);
    What is soundName when this happens?

  3. #3
    Member
    Join Date
    Jun 2011
    Posts
    85
    Line 106:

    Code:
    soundChannels[soundName].soundTransform = tempSoundTransform;
    soundName is something like this (when this error occurs): SOUND_LASER_ENEMY or SOUND_LASER_ENEMY2 or SOUND_LASER_ENEMY3 etc. etc.

    Besides of this I have to mention that the error occurs most often when my player is shooting or the enemy is shooting. Then the name is somethin like this:
    SOUND_LASER or SOUND_LASER2 or SOUND_LASER3 etc. etc.
    Last edited by drpelz; 04-19-2012 at 01:34 PM.

  4. #4
    Member
    Join Date
    Jun 2011
    Posts
    85
    Possible solution found:

    http://blog.curiousmedia.com/?q=blog...32-sounds-time

    I changed my code and until now all I can say is that my game runs very smoothly and no bugs so far. But I'm still testing my game so I'm not 100 percent sure if the bug is gone forever but it looks good...

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