我发现很难弄清楚 AS 3.0 中的引用系统。
这是我的代码(我已将其删减以找到问题,但无济于事)
package rpflash.ui {
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.Stage;
import nowplaying;
import flash.text.TextField;
public class RPUserInterface extends Sprite{
var np:nowplaying;
public function RPUserInterface(){
}
public function init(){
var np:nowplaying = new nowplaying();
this.addChild(np)
}
public function updateplayer(xml:XML){
var artist: String = xml.nowplaying.artist.toString();
var title: String = xml.nowplaying.title.toString();
trace("UI:update");
trace(this.np);// this gives me a null reference
}
}
}
但我仍然无法访问 np!!!跟踪 this.np 给我一个空引用。我什至不想从子类中访问它。 (顺便说一句,我也想知道如何做到这一点。)
最佳答案
在 init()
函数中,您正在实例化一个名为 np
的局部变量。试试这个:
public function init() {
// var np:nowplaying = new nowplaying();
np = new nowplaying();
this.addChild(np);
}
此外,请确保在 updateplayer()
之前调用 init()
。希望有帮助。
关于actionscript-3 - AS 3.0引用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2613182/