# Calling a function from within sound.onLoad()

**URL:** <https://forum.kirupa.com/t/calling-a-function-from-within-sound-onload/238480>\
**Category:** flash\
**Created:** [September 11, 2007, 7:14pm UTC](https://forum.kirupa.com/t/calling-a-function-from-within-sound-onload/238480 "2007-09-11T19:14:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![infect](https://avatars.discourse-cdn.com/v4/letter/i/c6cbf5/32.png) [@infect](https://forum.kirupa.com/u/infect)\
**Post date:** [September 11, 2007, 7:14pm UTC](https://forum.kirupa.com/t/calling-a-function-from-within-sound-onload/238480/1 "2007-09-11T19:14:20Z")

</div>

So I’m trying to call a function from the onLoad method of my sound object and something is wrong with my scope. I’m not sure how to solve this because I can’t assign it a listener and I’m not sure what else to do.

see my example…

```auto
class com.infect.SoundController{
    
    private var soundObject:Sound
    private var soundMC:MovieClip
    
    public function SoundController(){
        trace("SoundControl Initialized")

        soundObject = new Sound()
        //soundObject.owner = this
        soundMC = _root.createEmptyMovieClip("soundMC",_root.getNextHighestDepth())
        
        soundMC.soundObject = soundObject
        
        
        
        loadNewSound("mysound.mp3")
    }

    private function loadNewSound(newSoundFile):Void{
        

        soundObject.onLoad = function(success){
            trace("SoundControl.Events.soundLoaded()" + this)
            if(success){
                //I want to call fadeSoundIn() from here but I can't due to scope, please help
                fadeSoundIn()
            }else{
                trace("I hate sounds")
            }
        }
        
        soundObject.loadSound(newSoundFile, true)
        
    }
    
    private function fadeSoundIn():Void{
        trace("SoundControl.fadeSoundIn()")
    }
    

}

```

I’m stumped…  
:h:
