Skip to main content
November 10, 2014
Question

TypeError: Error #1009: Cannot access a property or method of a null object reference. at Sound_fla::MainTimeline/goReturn()

  • November 10, 2014
  • 1 reply
  • 206 views

The situation is the page will go back when the music starts. But if the music is not on, the error comes out and it will not go back. This is my action script for the page:

import flash.media.Sound;

import flash.net.URLRequest;

import flash.media.SoundChannel;

import flash.events.MouseEvent;

var my_songs:XMLList;

var my_total:Number;

var my_sound:Sound;

var my_channel:SoundChannel;

var current_song:Number = 0;

var song_position:Number;

var song_paused:Boolean;

var myXMLLoader:URLLoader = new URLLoader();

myXMLLoader.load(new URLRequest("playlist.xml"))

myXMLLoader.addEventListener(Event.COMPLETE, processXML);

function processXML (event:Event):void{

  var myXML:XML = new XML(event.target.data);

my_songs = myXML.SONG;

my_total = my_songs.length();

myXMLLoader.removeEventListener(Event.COMPLETE, processXML);

myXMLLoader = null;

}

function playSong(mySong:Number):void{

  var myTitle = my_songs[mySong].@TITLE;

  var myArtist = my_songs[mySong].@ARTIST;

  var myURL = my_songs[mySong].@URL;

title_txt.text = myTitle;

artist_txt.text = myArtist;

if (my_channel){

  my_channel.stop();

  my_channel.removeEventListener(Event.SOUND_COMPLETE, nextSound);

}

my_sound = new Sound();

my_sound.load(new URLRequest(myURL));

my_channel = my_sound.play();

my_channel.addEventListener(Event.SOUND_COMPLETE, nextSound);

}

nextBtn.addEventListener(MouseEvent.CLICK, nextSound);

function nextSound(event:Event):void{

  current_song++;

  if (current_song>=my_total){

  current_song=0;

  }

  playSong(current_song);

}

prevBtn.addEventListener(MouseEvent.CLICK, prevSound);

function prevSound(event:MouseEvent):void{

  current_song--;

  if (current_song<0){

  current_song = my_total-1;

  }

  playSong(current_song);

}

pauseBtn.addEventListener(MouseEvent.CLICK, pauseSound);

function pauseSound(event:MouseEvent):void{

  if (my_channel){

  song_position = my_channel.position;

  my_channel.stop();

  song_paused=true;

  }

}

playBtn.addEventListener(MouseEvent.CLICK, playSound);

function playSound(event:MouseEvent):void{

  if (song_paused){

  my_channel = my_sound.play(song_position);

  song_paused=false;

  } else if (!my_channel){

  playSong(current_song);

  }

}

backBtn.addEventListener(MouseEvent.CLICK, goReturn)

function goReturn (event:MouseEvent):void{

  my_channel.stop();

  var request:URLRequest = new URLRequest("Home.swf");

  var myLoader:Loader = new Loader();

  myLoader.load(request);

  addChild(myLoader);

}

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
November 11, 2014

The 1009 error indicates that one of the objects being targeted by your code is out of scope.

 

If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.