samedi 21 janvier 2017

Checking a Boolean variable in another class

Let me set the stage because it's too much code to post everything:

I have a that is setting up my so I can trigger sounds from any other class ( has all the functions needed to call all my sounds as needed)

I have a that can access these sounds by using docRef.soundControl.laserFire or whatever other function name I want, and in this case the laserFire sound would trigger once.

So here is my question. I want to let this laser sound effect finish playing before you can fire another laser. So in I've set up the following pieces of code:

private var _laserPlaying:Boolean = false;

internal function laserFire():void {
    _sfxChannel =;
    _sfxChannel.addEventListener(Event.SOUND_COMPLETE, laserFinished);

internal function laserFinished():void {
    _sfxChannel.removeEventListener(Event.SOUND_COMPLETE, laserFinished);

public function get laserPlaying():Boolean {
    return _laserPlaying;

public function set laserPlaying(value:Boolean):void {
    _laserPlaying = value;

Now in my enterFrameHandler function I want to do an

if (docRef.soundControl.laserPlaying()==false)

or something to that effect so I can check when the sound is done and allow the player to once again press the trigger to fire the laser. So far any variant I've tried on this either gives me an error (in this case 1195; Attempted access of inaccessible method laserPlaying through a reference with static type SoundController) or it actually compiles but after firing the first laser shot it never allows the trigger to be pressed again. So I'm obviously doing something wrong and am hoping someone can help.

Let me just state that the laser sound is playing just fine that first time, so don't worry about all the code I'm not bothering to show to make that portion of the code work. However, if more info is needed to understand how I'm making anything work just let me know. And Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire