program for Drawing a Rectangle - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Friday, October 7, 2011

program for Drawing a Rectangle


 Drawing a Rectangle
--------------------------------------


(a)       Rectangle.as               file
class Rectangle
{
private var width:Number;
private var height:Number;
private var mc:MovieClip;
public function Rectangle(w:Number,h:Number,x:Number,y:Number,target:MovieClip,depth:Number)
{
mc=target.createEmptyMovieClip("boxcontainer"+depth,depth);
setWidth(w);
setHeight(h);
setX(x);
setY(y);
}
public function getWidth():Number
{
return width;
}
public function setWidth(w:Number):Void
{
width=w;
draw();
}
public function getHeight():Number
{
return height;
}
public function setHeight(h:Number):Void
{
height=h;
draw();
}
public function getX():Number
{
return mc._x;
}
public function setX(x:Number):Void
{
mc._x=x;
}
public function getY():Number
{
return mc._y;
}
public function setY(y:Number):Void
{
mc._y=y;
}
public function draw():Void
{
mc.clear();
mc.lineStyle(1,0x000000);
mc.moveTo(0,0);
mc.beginFill(0xffffff,100);
mc.lineTo(width,0);
mc.lineTo(width,height);
mc.lineTo(0,height);
mc.lineTo(0,0);
mc.endFill();
}
}
------------------------------------------------------------------------------------
(b)   Rectangle.fla           file
-----------------------------------------------------------------------------------
var b:Rectangle=new Rectangle(250,260,100,110,this,1);







No comments:

Post a Comment