SoundManager - Pausing Sound by referenceing code in seperate .AS file

Okay, so because of the way this game has been built the whole game world is initialized on game start up. I wanted to have this Zombie Penguin enemy use a walk sound (it would be odd if he moved and was silent) but because it is initializing the whole world, simply coding the sound into his animation state won’t work because it will play the sound for every existing Zombie Penguin in the world, not just the one on the screen.

Now I’ve tried to get around this problem by using a SoundManager class (http://evolve.reintroducing.com/2008/07/15/as3/as3-soundmanager/) to load and play/pause the sound when necessary. I’ve got this working by placing a movieclip above the world and hittesting everything and when it finds a Zombie Penguin activates the SFX. If it finds the enemy and you leave the room or kill the enemy (basically any way it is removed from the screen) it will pause the sound (not stop) and then unpause if you go back/find another instance of that enemy.

The problem is, though, that if I STUN the enemy (not kill it) it plays it’s dizzy animation (which consists of hit sitting down with stars spinning around it’s head) the walking SFX continues to play as the enemy is still on the screen.

Now in the Zombie Penguins .as file it has a boolean that for being stunned or not (bStunned), and a function (public function getZPStun():Boolean – returns bStunned).

I figure that I just have to reference that somewhere in the following code, but I’m not sure where. The Zombie Penguin’s .as is ZPEnemy, so I’m calling it like so:

**ZPEnemy.getInstance().getZPStun() **

I’ve tried calling it as part of an if statement a in a number of places, saying that is getZPStun == true then pause the sound, but I can’t seem to get it to work. I’m not even sure that’s the proper way about this, which is why I’m posting here. I’m using:

Anyone have a clue how to fix this?


var bNotPenguin = true;

for(var i = 0; i<this.numChildren; i++)              //** Sound Manager Coding (May 15)
      {
           if(parent.roomFinder_mc.hitTestObject(this.getChildAt(i)))
           {
                if(!(this.getChildAt(i) is Wally_mc) && !(this.getChildAt(i) is Joe_mc) && !(this.getChildAt(i) is Shape))
                {
                     for(var j = 0; j < this.getChildAt(i).numChildren; j++)
                     {
                          if(this.getChildAt(i).getChildAt(j) is ZombiePenguin)
                          {
                               if(!(SoundManager.getInstance().getSoundPosition("ZombiePenguin_walk")<SoundManager.getInstance().getSoundDuration("ZombiePenguin_walk"))||(!bZombieInitialized))
                                    {
                                        SoundManager.getInstance().playSound("ZombiePenguin_walk");
                                        bZombieInitialized = true;
                                    }
                                
                          else if    (SoundManager.getInstance().isSoundPaused("ZombiePenguin_walk"))
                          {
                               SoundManager.getInstance().playSound("ZombiePenguin_walk");
                               bZombieInitialized = true;
                          }
                                
                          bNotPenguin = false;
                    }
                }
                        
                if(bNotPenguin == true)
                {
                     trace("paused")
                     SoundManager.getInstance().pauseSound("ZombiePenguin_walk");
                }
                        
                else
                {
                     trace("NOT paused")
                }
           }
      }
  }