# More help with my code please

**URL:** <https://forum.kirupa.com/t/more-help-with-my-code-please/300236>\
**Category:** flash\
**Created:** [November 18, 2009, 1:35am UTC](https://forum.kirupa.com/t/more-help-with-my-code-please/300236 "2009-11-18T01:35:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonstle](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@jonstle](https://forum.kirupa.com/u/jonstle)\
**Post date:** [November 18, 2009, 1:35am UTC](https://forum.kirupa.com/t/more-help-with-my-code-please/300236/1 "2009-11-18T01:35:25Z")

</div>

I am working with AS3, trying to put together my first major (at least for me) app. As you might assume I am using tutorials and books to help me get things done which can lead to issues. That is where I am now.

I am trying to figure out the following error message without much luck:

[INDENT]TypeError: Error #1009: Cannot access a property or method of a null object reference.  
at latestMessage\_fla::MainTimeline/startAudioPlayer()  
at latestMessage\_fla::MainTimeline/ParseBooks()  
at latestMessage\_fla::MainTimeline/LoadXML()  
at flash.events::EventDispatcher/dispatchEventFunction()  
at flash.events::EventDispatcher/dispatchEvent()  
at [flash.net](http://flash.net)::URLLoader/onComplete()

[/INDENT]I am sure there is something goofy with my code and have found the line that is creating the error message but I have no idea if it is the real cause, or just wishful thinking on my part.

Here is my code, I have marked the line I think is the cause of everything but I am not sure about that at all:

\*var xmlLoader:URLLoader = new URLLoader();  
var xmlData:XML;  
var audioFile:String;  
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);  
xmlLoader.load(new URLRequest(“[http://www.rivervalleychurch.net/sermonaudio/Podcast/podcast.xml](http://www.rivervalleychurch.net/sermonaudio/Podcast/podcast.xml)”));

function LoadXML(e:Event):void {  
xmlData = new XML(e.target.data);  
ParseBooks(xmlData);  
}

//Load text into text fields  
function ParseBooks(podcastInput:XML):void {  
description\_txt.text = (podcastInput.channel.item.description.text()[0]);  
title\_txt.text = (podcastInput.channel.item.title.text()[0]);  
publish\_txt.text = (podcastInput.channel.item.pubDate.text()[0]);

```
// not sure if the url type was wrong here, but forcing it to string
audioFile = (podcastInput.channel.item.link.text()[0].toString());
//trace(audioFile);

startAudioPlayer();

```

}

//Audio Player Controls and Stuff  
var req:URLRequest;  
var sound:Sound;  
var controller:SoundChannel;  
var volumeControl:SoundTransform;  
var resumeTime:Number = 0;

function startAudioPlayer():void  
{  
req = new URLRequest(audioFile);  
if(controller)  
{  
controller.stop();  
}

```
[U] **//The line below is causing problems** [/U]
volumeControl = controller.soundTransform;
sound = new Sound();
sound.load(new URLRequest(audioFile));
pause_btn.visible = false;

play_btn.addEventListener(MouseEvent.CLICK, playSound);
pause_btn.addEventListener(MouseEvent.CLICK, stopSound);
volumeUp_btn.addEventListener(MouseEvent.CLICK, volumeUp);
volumeDown_btn.addEventListener(MouseEvent.CLICK, volumeDown);

```

}

function playSound(event:MouseEvent):void {  
controller = sound.play(resumeTime);  
play\_btn.visible = false;  
pause\_btn.visible = true;  
}

function stopSound(event:MouseEvent):void {  
resumeTime = controller.position;  
controller.stop();  
play\_btn.visible = true;  
pause\_btn.visible = false;  
}

function volumeUp(event:MouseEvent): void  
{  
volumeControl.volume += .1;  
if(volumeControl.volume \> 1)  
{  
volumeControl.volume = 1;  
}  
controller.soundTransform = volumeControl;  
}

function volumeDown(event:MouseEvent): void  
{  
volumeControl.volume -= .1;  
if(volumeControl.volume \< 0)  
{  
volumeControl.volume = 0;  
}  
controller.soundTransform = volumeControl;  
}

//Event Listeners For buttons  
itunes\_btn.addEventListener(MouseEvent.CLICK, goItunes);  
archives\_btn.addEventListener(MouseEvent.CLICK, goArchives);  
rss\_btn.addEventListener(MouseEvent.CLICK, goRss);

//Functions For Buttons  
function goItunes(e:MouseEvent):void{  
navigateToURL(new URLRequest(“[http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id=262248424](http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id=262248424)”));  
}  
function goArchives(e:MouseEvent):void{  
navigateToURL(new URLRequest(“[http://www.rivervalleychurch.net/index.php?option=com\_content&view=category&layout=](http://www.rivervalleychurch.net/index.php?option=com_content&view=category&layout=) blog&id=37&Itemid=91”));  
}  
function goRss(e:MouseEvent):void{  
navigateToURL(new URLRequest(“[http://www.rivervalleychurch.net/sermonaudio/Podcast/podcast.xml](http://www.rivervalleychurch.net/sermonaudio/Podcast/podcast.xml)”));  
}  
\*

Any thoughts or ideas I can get on this would be great!

[size=1][color=red]\*\*modEdit: here’s the same code wrapped in [noparse]

```auto

```

[/noparse] tags:\*\*[/color][/size]

```auto
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML;
var audioFile:String;
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("http://www.rivervalleychurch.net/sermonaudio/Podcast/podcast.xml"));

function LoadXML(e:Event):void {
    xmlData = new XML(e.target.data);
    ParseBooks(xmlData);
}

//Load text into text fields
function ParseBooks(podcastInput:XML):void {
    description_txt.text = (podcastInput.channel.item.description.text()[0]);
    title_txt.text = (podcastInput.channel.item.title.text()[0]);
    publish_txt.text = (podcastInput.channel.item.pubDate.text()[0]);
   
    // not sure if the url type was wrong here, but forcing it to string
    audioFile = (podcastInput.channel.item.link.text()[0].toString());
    //trace(audioFile);
   
    startAudioPlayer();
}

//Audio Player Controls and Stuff
var req:URLRequest;
var sound:Sound;
var controller:SoundChannel;
var volumeControl:SoundTransform;
var resumeTime:Number = 0;

function startAudioPlayer():void 
{
    req = new URLRequest(audioFile);
    if(controller)
    {
        controller.stop();
    }
    
    [U] **//The line below is causing problems** [/U]
    volumeControl = controller.soundTransform;
    sound = new Sound();
    sound.load(new URLRequest(audioFile));
    pause_btn.visible = false;
   
    play_btn.addEventListener(MouseEvent.CLICK, playSound);
    pause_btn.addEventListener(MouseEvent.CLICK, stopSound);
    volumeUp_btn.addEventListener(MouseEvent.CLICK, volumeUp);
    volumeDown_btn.addEventListener(MouseEvent.CLICK, volumeDown);
    
}

function playSound(event:MouseEvent):void {
    controller = sound.play(resumeTime);
    play_btn.visible = false;
    pause_btn.visible = true;
}

function stopSound(event:MouseEvent):void {
    resumeTime = controller.position;
    controller.stop();
    play_btn.visible = true;
    pause_btn.visible = false;
}

function volumeUp(event:MouseEvent): void
{
    volumeControl.volume += .1;
    if(volumeControl.volume > 1)
    {
        volumeControl.volume = 1;
    }
    controller.soundTransform = volumeControl;
}

function volumeDown(event:MouseEvent): void
{
    volumeControl.volume -= .1;
    if(volumeControl.volume < 0)
    {
        volumeControl.volume = 0;
    }
    controller.soundTransform = volumeControl;
}

//Event Listeners For buttons
itunes_btn.addEventListener(MouseEvent.CLICK, goItunes);
archives_btn.addEventListener(MouseEvent.CLICK, goArchives);
rss_btn.addEventListener(MouseEvent.CLICK, goRss);

//Functions For Buttons
function goItunes(e:MouseEvent):void{
    navigateToURL(new URLRequest("http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id=262248424"));
}
function goArchives(e:MouseEvent):void{
    navigateToURL(new URLRequest("http://www.rivervalleychurch.net/index.php?option=com_content&view=category&layout= blog&id=37&Itemid=91"));
}
function goRss(e:MouseEvent):void{
    navigateToURL(new URLRequest("http://www.rivervalleychurch.net/sermonaudio/Podcast/podcast.xml"));
}

```
