AS 3.0 reference issue

I am having a hard time finding help system in AS 3.0.

this is the code i have (i trimmed it 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 yet i cant access np !!! trace this.np gives me a null reference. I am not even trying to access it from a sub-language class. (btw i def want to know how to do this.)

+2


source to share


1 answer


In your function, init()

you create a local variable named np

. Try this instead:

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

      



Also, make sure you init()

get the call before updateplayer()

. Hope it helps.

+3


source







All Articles