PDA

View Full Version : class works, even no import of graphics class?


conspirisi
01-22-2009, 05:13 PM
Why does this class work even though I haven't imported the graphics class?

package {
import flash.display.MovieClip;
public class Rect extends MovieClip{
private var xPos:Number;
private var yPos:Number;
public function Rect(xPos:Number,yPos:Number) {
graphics.beginFill( 0x0099FF , 1 );
graphics.drawRect( 20 , 20 , 20,20 );
graphics.endFill( );
trace ("Rect falls")
x = xPos;
y = yPos;
}
}
}

senocular
01-22-2009, 05:20 PM
You only need to import classes you call directly by name. Here, you're not using the class, you're using a predefined instance of the class named graphics. It was the responsibility of MovieClip to actually instantiate that object, and if you could look at its class code (if it had class code), MovieClip would have imported Graphics since it would need to call out to Graphics directly to make the instance of the graphics property.

conspirisi
01-22-2009, 05:42 PM
thanks senocular,

Is there a quick way of discovering if I'm using a predefined instance of a class, that you mention? Is it that the graphics class a subclass of MovieClip?

conspirisi
01-22-2009, 05:50 PM
ok i see graphics class is not a subclass of MovieClip