A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Strange sound error

Threaded View

  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.

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