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::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”));
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”));
}
*
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]
[/noparse] tags:**[/color][/size]
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"));
}