as3.0 无法访问空对象引用的属性或方法,急! 30

是一个实现控制声音的项目,源代码如下:varsnd:Sound;varchannel:SoundChannel;vartrans:SoundTransform;varcu... 是一个实现控制声音的项目,源代码如下:
var snd:Sound;
var channel:SoundChannel;
var trans:SoundTransform;
var currSong:String;
var currVol:Number = 0.5;
var currPan:Number = 0;
var songList:Array = new Array("Bruno Mars - Just The Way You Are.mp3","Carol+of+The+Bells.mp3","Dia Frampton - Walk Away.mp3","Fooling+Mode.mp3","冰菊物语%28古筝版%29-《舌尖上的中国》原声.mp3");
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;
}
panSlider.visible = false;
volSlider.visible = false;
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);
function chooseSong(e:MouseEvent):void
{
switch (e.currentTarget.name)
{
case "song1" :
currSong = "../mp3/" + songList[0] as String;
break;
case "song2" :
currSong = "../mp3/" + songList[1] as String;
break;
case "song3" :
currSong = "../mp3/" + songList[2] as String;
break;
case "song4" :
currSong = "../mp3/" + songList[3] as String;
break;
case "song5" :
currSong = "../mp3/" + songList[4] as String;
break;
}
if (snd!=null)
{
channel.stop();
snd=new Sound();
}
snd.load(new URLRequest(currSong));
channel = new SoundChannel() ;
trans = new SoundTransform(currVol,currPan);
channel = snd.play();
channel.soundTransform = trans;
}
展开
 我来答
匿名用户
2015-02-10
展开全部
var clip = this["song" + (i + 1)].title;
clip.text = str;

你这个自己声明的clip是什么来的 感觉就是场景上的一个文本框 但你又var 干啥?
更多追问追答
追问
对于新出现的变量,当然需要var来声明吧,把var去掉只会增加新的错误,即clip未定义。这里是将实例名为title的文本框赋给它,就算是把这两句注释掉,改成this["song" + (i + 1)].title.text = str;同样也会报同样的错的!
追答
你最好还是上传你的源文件吧(外部音乐不需要) ,我也是打开flash重建你的元件来运行的,你不上传,也不好分析
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式