DBC
DBC

Reputation: 69

AS3 accessing stage from class

Timeline code:

import as3.first;

first._this=this;

var str1:String='this is timeline';

Class code:

package as3 {

import flash.display.MovieClip;

public class first extends MovieClip {

public static var _this:Object;

trace(_this.str1);

}

}

Error message:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

Trying to wrap my mind around how classes work. Need to access timeline functions and variables from class. What am I doing wrong and how can I make this work?

Upvotes: 0

Views: 231

Answers (1)

Michael Antipin
Michael Antipin

Reputation: 3532

All in all what you are doing is somewhat weird. May be, you just want a document class for your SWF root? You as well could add a class to any movieclip in your library: both ways grant you access to timeline.

package as3 
{
    import flash.display.MovieClip;
    public class first extends MovieClip 
    {
        public static var _this:Object;
        trace(_this.str1); // you may place code here... but consider this:
                           // this area is STATIC, the code here 
                           // executes only once when class gets initialized,
                           // so, this happens BEFORE you assign first._this=this;
    }
}

Upvotes: 2

Related Questions