mcgiddin
06-04-2005, 01:34 AM
I'm trying to create a class that builds a box for me, I have thron together a quick class that draws the box, but it will only draw if I use _root.lineStyle... If I use "this" instead of "_root" I get nothing. I'm thinking I need to create a movieclip for my class but I'm not sure how to go about doing so. Below is my code and where its placed, either in the movie or an external class.
main.fla layer:1 frame:1
var box:MovieClip = new Box();
box._x = 0;
box._y = 50;
box._width = 150;
box._height = 499;
box._lineSize = 1;
box._lineColor = 0x000000;
box._lineAlpha = 100;
box._boxFill = 0xA6FFDB;
box._boxAlpha = 100;
box.draw(); // doesn't draw the box unless I use _root... in the class.
this.createEmptyMovieClip("logo_mc", this.getNextHighestDepth() );
this.createEmptyMovieClip("login_mc", this.getNextHighestDepth() );
this.createEmptyMovieClip("bodyFrame_mc", this.getNextHighestDepth() );
logo_mc.loadMovie("../logo/logo.swf");
logo_mc._x = 0;
logo_mc._y = 0;
login_mc.loadMovie("../login/login.swf");
login_mc._x = 0;
login_mc._y = 130;
bodyFrame_mc.loadMovie("../bodyFrame/bodyFrame.swf");
bodyFrame_mc._x = 150;
bodyFrame_mc._y = 50;
stop();
Box.as
import mx.events.EventDispatcher;
class Box extends MovieClip {
public var _x:Number;
public var _y:Number;
public var _width:Number;
public var _height:Number;
public var _lineSize:Number;
public var _lineColor:Number;
public var _lineAlpha:Number;
public var _boxFill:Number;
public var _boxAlpha:Number;
private var fillBox:Boolean = false;
private var _x1:Number;
private var _y1:Number;
private var _x2:Number;
private var _y2:Number;
private var debug:Boolean = true;
function Box() {
EventDispatcher.initialize(this);
if( this.debug ) {
trace( "in Box()" );
}
}
function draw() {
if( this.debug ) {
trace("now in Box.draw");
}
this._x1 = this._x;
this._y1 = this._y;
this._x2 = this._x + this._width;
this._y2 = this._y + this._height;
if( this._boxFill != NaN ) {
if( this._boxAlpha == NaN ) {
this._boxAlpha = 100;
}
this.fillBox = true;
}
if( this.debug ) {
trace( "this._x1 = " + this._x1 );
trace( "this._y1 = " + this._y1 );
trace( "this._x2 = " + this._x2 );
trace( "this._y2 = " + this._y2 );
trace( "this._boxFill = " + this._boxFill );
trace( "this._boxAlpha = " + this._boxAlpha );
trace( "this.fillBox = " + this.fillBox );
trace( "this._lineSize = " + this._lineSize );
trace( "this._lineColor = " + this._lineColor );
trace( "this._lineAlpha = " + this._lineAlpha );
}
this.lineStyle( this._lineSize, this._lineColor, this._lineAlpha ); // doesn't work unless I use "_root" in place of "this"
this.moveTo( this._x1, this._y1 ); // doesn't work unless I use "_root" in place of "this"
if( this.fillBox ) {
this.beginFill( this._boxFill, this._boxAlpha); // doesn't work unless I use "_root" in place of "this"
}
this.lineTo( this._x1, this._y2); // doesn't work unless I use "_root" in place of "this"
this.lineTo( this._x2, this._y2); // doesn't work unless I use "_root" in place of "this"
this.lineTo( this._x2, this._y1); // doesn't work unless I use "_root" in place of "this"
this.lineTo( this._x1, this._y1); // doesn't work unless I use "_root" in place of "this"
if( this.fillBox ) {
this.endFill(); // doesn't work unless I use "_root" in place of "this"
}
}
}
main.fla layer:1 frame:1
var box:MovieClip = new Box();
box._x = 0;
box._y = 50;
box._width = 150;
box._height = 499;
box._lineSize = 1;
box._lineColor = 0x000000;
box._lineAlpha = 100;
box._boxFill = 0xA6FFDB;
box._boxAlpha = 100;
box.draw(); // doesn't draw the box unless I use _root... in the class.
this.createEmptyMovieClip("logo_mc", this.getNextHighestDepth() );
this.createEmptyMovieClip("login_mc", this.getNextHighestDepth() );
this.createEmptyMovieClip("bodyFrame_mc", this.getNextHighestDepth() );
logo_mc.loadMovie("../logo/logo.swf");
logo_mc._x = 0;
logo_mc._y = 0;
login_mc.loadMovie("../login/login.swf");
login_mc._x = 0;
login_mc._y = 130;
bodyFrame_mc.loadMovie("../bodyFrame/bodyFrame.swf");
bodyFrame_mc._x = 150;
bodyFrame_mc._y = 50;
stop();
Box.as
import mx.events.EventDispatcher;
class Box extends MovieClip {
public var _x:Number;
public var _y:Number;
public var _width:Number;
public var _height:Number;
public var _lineSize:Number;
public var _lineColor:Number;
public var _lineAlpha:Number;
public var _boxFill:Number;
public var _boxAlpha:Number;
private var fillBox:Boolean = false;
private var _x1:Number;
private var _y1:Number;
private var _x2:Number;
private var _y2:Number;
private var debug:Boolean = true;
function Box() {
EventDispatcher.initialize(this);
if( this.debug ) {
trace( "in Box()" );
}
}
function draw() {
if( this.debug ) {
trace("now in Box.draw");
}
this._x1 = this._x;
this._y1 = this._y;
this._x2 = this._x + this._width;
this._y2 = this._y + this._height;
if( this._boxFill != NaN ) {
if( this._boxAlpha == NaN ) {
this._boxAlpha = 100;
}
this.fillBox = true;
}
if( this.debug ) {
trace( "this._x1 = " + this._x1 );
trace( "this._y1 = " + this._y1 );
trace( "this._x2 = " + this._x2 );
trace( "this._y2 = " + this._y2 );
trace( "this._boxFill = " + this._boxFill );
trace( "this._boxAlpha = " + this._boxAlpha );
trace( "this.fillBox = " + this.fillBox );
trace( "this._lineSize = " + this._lineSize );
trace( "this._lineColor = " + this._lineColor );
trace( "this._lineAlpha = " + this._lineAlpha );
}
this.lineStyle( this._lineSize, this._lineColor, this._lineAlpha ); // doesn't work unless I use "_root" in place of "this"
this.moveTo( this._x1, this._y1 ); // doesn't work unless I use "_root" in place of "this"
if( this.fillBox ) {
this.beginFill( this._boxFill, this._boxAlpha); // doesn't work unless I use "_root" in place of "this"
}
this.lineTo( this._x1, this._y2); // doesn't work unless I use "_root" in place of "this"
this.lineTo( this._x2, this._y2); // doesn't work unless I use "_root" in place of "this"
this.lineTo( this._x2, this._y1); // doesn't work unless I use "_root" in place of "this"
this.lineTo( this._x1, this._y1); // doesn't work unless I use "_root" in place of "this"
if( this.fillBox ) {
this.endFill(); // doesn't work unless I use "_root" in place of "this"
}
}
}