Skip to main content
Known Participant
June 23, 2009
Answered

How to create rectangular Box object through pure action script.

  • June 23, 2009
  • 2 replies
  • 942 views

How to create rectangular Box object through pure action script ?

I think, it can be done through the libary of movie clip but I am not sure. Please, I want to take suggestion to create rectangular box through AS script

This topic has been closed for replies.
Correct answer

Take a new file and on first frame write the code below it is working fine:

var rect = new Shape();
rect.graphics.beginFill(0xFF0000);
rect.graphics.drawRect(0, 0, 100,50);
rect.graphics.endFill();

var mc = new MovieClip();
mc.addChild(rect);
addChild(mc);

If that doesn't solve your problem then paste the error you are getting

2 replies

actionscript5
Inspiring
June 24, 2009

Here you can use the below code to make a rectangle from actionscript

var myObj = new Shape();

//giving color to the object

myObj.graphics.beginFill(0xFF0000);

//drawing rectangle

myObj.graphics.draw.rect(0, 0, 200, 300 );

myObj.graphics.endFill();

//displaying on the stage

addChild(myObj);

Enjoy it

June 23, 2009

Please see the code snippet below:

var rect = new Shape();
rect.graphics.beginFill(0xFF0000);
rect.graphics.drawRect(0, 0, 100,50);
rect.graphics.endFill();

var mc:MovieClip = new MovieClip();

mc.addChild(rect);

This will create a filled rectangle for you with width 100 and height 50 and color 0xFF0000 i.e. RED.

You can draw and empty rectangle using lineTo method of Graphics class in the same way above.

nepaliktoAuthor
Known Participant
June 24, 2009

Hi ! SwapnilVJ,

Your code are fine but there is still problem on converting into movie clip

import flash.display.Sprite;
import flash.display.Shape;
import flash.display.MovieClip;

var rect = new Shape();
rect.graphics.beginFill(0xFF0000);
rect.graphics.drawRect(0, 0, 100,50);
rect.graphics.endFill();
addChild(rect);


/*
var mc:MovieClip = new MovieClip();

mc.addChild(rect);
*/

If, I remove comment then it show error whiel I converting into movie clip, what was the problem on this code.

Correct answer
June 24, 2009

Take a new file and on first frame write the code below it is working fine:

var rect = new Shape();
rect.graphics.beginFill(0xFF0000);
rect.graphics.drawRect(0, 0, 100,50);
rect.graphics.endFill();

var mc = new MovieClip();
mc.addChild(rect);
addChild(mc);

If that doesn't solve your problem then paste the error you are getting