繁体   English   中英

AS3 TypeError:错误#1009:无法访问空对象引用的属性或方法

[英]AS3 TypeError: Error #1009: Cannot access a property or method of a null object reference

我(以及在此处发布问题的其他所有人)对AS3AS3 因此,我很疯狂,试图找出导致此错误的原因。 我有一个“自动点唱机”播放器,可在单击按钮时相应地加载歌曲。 但是这是我的错误:

TypeError:错误#1009:无法访问空对象引用的属性或方法。 在课09_V2_S5_fla :: MainTimeline / frame1()

这是我的代码:

import fl.events.SliderEvent;

var snd:Sound;
var channel:SoundChannel;
var trans:SoundTransform;

//create variables to store values for the current song and it's volume and pan        settings.
var currSong:String;
var currVol:Number = .5;
var currPan:Number = 0;

// Array of all the songs in the current playlist.
var songList:Array=new Array("Nothing On You.mp3","Grenade.mp3","Ride.mp3","Pretty       Girl Rock.mp3","Tick Tock.mp3","Dynamite.mp3");

// don't need to see the volume and pan controls until a song is playing
panSlide.visible=false;
volSlide.visible=false;

   //Listeners for the onstage song buttons
song1.addEventListener(MouseEvent.CLICK, chooseSong);
song2.addEventListener(MouseEvent.CLICK, chooseSong);
song3.addEventListener(MouseEvent.CLICK, chooseSong);
song4.addEventListener(MouseEvent.CLICK, chooseSong);
song5.addEventListener(MouseEvent.CLICK, chooseSong);
song6.addEventListener(MouseEvent.CLICK, chooseSong);

//listeners for the volume and pan sliders 
panSlide.addEventListener(SliderEvent.CHANGE, panChange);
volSlide.addEventListener(SliderEvent.CHANGE, volumeChange);


//sets the text field of all of the song buttons to display the names of the songs in      the songList array
for (var i = 0; i < songList.length; i++) {
    var str:String = songList[i] as String;
str = str.replace(".mp3","");
var clip = this["song" + (i + 1)].title;
clip.text = str;
  }

//switch statement to set the current song based on which song button was clicked.

function chooseSong(e:MouseEvent):void {
switch (e.currentTarget.name) {
    case "song1":
        currSong = "../MP3s/"+songList[0] as String;
        break;

    case "song2":
        currSong = "../MP3s/"+songList[1] as String;
        break;

    case "song3":
        currSong = "../MP3s/"+songList[2] as String;
        break;

    case "song4":
        currSong = "../MP3s/"+songList[3] as String;
        break;

    case "song5":
        currSong = "../MP3s/"+songList[4] as String;
        break;

    case "song6":
        currSong = "../MP3s/"+songList[5] as String;
        break;

if (snd != null) {
    channel.stop();
}
snd = new Sound();
snd.load(new URLRequest(currSong));
snd.addEventListener(IOErrorEvent.IO_ERROR, onError);

function onError(e:IOErrorEvent):void {
// Do nothing
}
}
}
channel = new SoundChannel  ;
trans = new SoundTransform(currVol,currPan);
channel = snd.play();
channel.soundTransform = trans;
panSlide.visible = true;
volSlide.visible = true;
//currVolume and pan values are used here for display in the text fields next to    sliders

volLabel.text = "Current Volume " + int(currVol * 100);
panLabel.text = "Current Pan " + int(currPan * 100);

//listens for arrival of ID3 tags
snd.addEventListener(Event.ID3, id3Handler);
 //triggered when id3 tags are available
 //sets info text field to display current song information from id3 tags.
 function id3Handler(event:Event):void {
var id3:ID3Info = snd.id3;
if (id3.songName != null) {
    songTitle.text = id3.songName + "\n";
    info.text="Artist: \n"+id3.artist+"\n \n";
    info.appendText("Album: \n" + id3.album);
    info.appendText("\n\n" + "Available at: \n" + "passionrecords \n.com");
}
}


var format:TextFormat = new TextFormat();
format.font = "Arial Black";
format.color = 0xFFFF00;
format.size = 14;
format.url = "http://www.passionrecords.com/";

info.defaultTextFormat = format;
// uses volume slider value to control volume
function volumeChange(e:SliderEvent):void {
currVol = e.target.value;
volLabel.text = "Current Volume: " + int(currVol*100);
trans.volume = currVol;
channel.soundTransform = trans;
 }


 function panChange(e:SliderEvent):void {
currPan = e.target.value;
panLabel.text = "Current Pan " + int(currPan*100);
trans.pan = e.target.value;
channel.soundTransform = trans;
 }

这是正确的。

第73行的错误是:snd = new Sound();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM