开发者

AS 3.0 reference problem

I am finding it hard to fugure out the reference system in AS 3.0.

this is the code i have (i have trimmed it down in order to find the problem but to no avail)

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
        }
}   
} 

and still i cannot access np!!! trace this.np gives me a null reference. i am not even trying to access it from a subling class. (btw i def wa开发者_如何学Gont to know how to do that as well.)


In your init() function, you are instantiating a local variable called np. Try this instead:

public function init() {
    // var np:nowplaying = new nowplaying();
    np = new nowplaying();
    this.addChild(np);
}

Also, make sure init() is getting called before updateplayer(). Hope that helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜