# Draw a box?

**URL:** <https://forum.kirupa.com/t/draw-a-box/5101>\
**Category:** Uncategorized\
**Created:** [August 31, 2002, 10:56pm UTC](https://forum.kirupa.com/t/draw-a-box/5101 "2002-08-31T22:56:22Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![finkman](https://avatars.discourse-cdn.com/v4/letter/f/bbe5ce/32.png) [@finkman](https://forum.kirupa.com/u/finkman)\
**Post date:** [August 31, 2002, 10:56pm UTC](https://forum.kirupa.com/t/draw-a-box/5101/1 "2002-08-31T22:56:22Z")

</div>

I am new to actionscript, and just want to do a very simple thing. I want to draw a line, 20 px wide, and x pixles high… so basicly what i need is a function to do that. I have tried to find a tutorial, but can’t find any tutorial that just describes this simple thing.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2002, 2:17am UTC](https://forum.kirupa.com/t/draw-a-box/5101/2 "2002-09-01T02:17:06Z")

</div>

you want to draw a lint 20px by x pixels thick? or you want to draw a box 20px wide by x pixels high??

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2002, 8:23am UTC](https://forum.kirupa.com/t/draw-a-box/5101/3 "2002-09-01T08:23:15Z")

</div>

a little illustration… =)

```
  20px

```

* * *

| |  
| |  
| |  
| |  
| |  
| |  
| |  
| |  
| |  
| | x px  
| |  
| |  
| |  
| |  
| |  
| |

| |
| --- |

it’s a line, 20 px thick and x pixles high.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2002, 8:31am UTC](https://forum.kirupa.com/t/draw-a-box/5101/4 "2002-09-01T08:31:21Z")

</div>

ok do this on the first frame of a new movie…

```php
_root.createEmptyMovieClip("foo",0);
_root.foo.lineStyle(20)
_root.foo.moveTo(275,50);
_root.foo.lineTo(275,250);

```

Ok if ur in mx that should work…if ur in flash 5 ur stuffed 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2002, 8:31am UTC](https://forum.kirupa.com/t/draw-a-box/5101/5 "2002-09-01T08:31:55Z")

</div>

I suppose you could create a MC which is a block 20px wide and 1px tall, then use actionscript to change the y scale of it to the size of your choice (using the this.\_yscale attribute). I am unsure if this is the best way to do it, but it should produce the effect youre looking for.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2002, 8:34am UTC](https://forum.kirupa.com/t/draw-a-box/5101/6 "2002-09-01T08:34:04Z")

</div>

yeah my example uses API (i dont know wot it means) to draw the line. If ur using flash mx u could have a look at the code and test it out 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2002, 9:15am UTC](https://forum.kirupa.com/t/draw-a-box/5101/7 "2002-09-01T09:15:28Z")

</div>

Here is what you asked for, a function using a Drawing API Method:

```auto
**function lineScript(xpos, thick, height, color) {
	_root.createEmptyMovieClip("line_clip", 0);
	line_clip.lineStyle(thick, color);
	line_clip.moveTo(xpos, 50);
	line_clip.lineTo(xpos, height + 50);
}**

```

Now put this on a frame, button, or movie clip:

```auto
**lineScript(50, 10, 100, 0xFF0000);**

```

**Definitions:**  
**xpos:** the \_x postion of your line.  
**thick:** how thick you want your line.  
**height:** obviously the height of your line.  
**color:** the color of your line in HEX format, but remember that Flash needs “0x” before the actual HEX, so refer to what I did above!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2002, 10:53am UTC](https://forum.kirupa.com/t/draw-a-box/5101/8 "2002-09-01T10:53:39Z")

</div>

isn’t that what i said? 🙂 hehe

I didin put the colour and stuff like that in though… but yeah close enough…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2002, 1:40pm UTC](https://forum.kirupa.com/t/draw-a-box/5101/9 "2002-09-01T13:40:48Z")

</div>

Yep, if you’re using MX, your best shot in the drawing API. But you use Flash 5, you might want to take a look at the drawing board tutorial on this site. It explains how to do that.

pom :asian:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2002, 1:45pm UTC](https://forum.kirupa.com/t/draw-a-box/5101/10 "2002-09-01T13:45:02Z")

</div>

And one more thing, your function is nice Dan, but the problem is you can use it only once: you use depth 0 to draw the line all the time.

pom :asian:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2002, 5:52pm UTC](https://forum.kirupa.com/t/draw-a-box/5101/11 "2002-09-01T17:52:34Z")

</div>

I hate forgetting things, so here is the edited function:

**Place this on your root timeline:**

```auto
**i = 0;

function lineScript(xpos, ystart, thick, height, color) {
	_root.createEmptyMovieClip("line_clip", i);
	line_clip.lineStyle(thick, color);
	line_clip.moveTo(xpos, ystart);
	line_clip.lineTo(xpos, height + ystart);
	i++;
}**

```

**Example of how to execute function:**

```auto
**_root.lineScript(25, 75, 5, 50, 0xFF9900);
_root.lineScript(50, 50, 10, 100, 0xFF0000);
_root.lineScript(75, 75, 5, 50, 0xFF9900);**

```

**Definitions:**  
**i:** variable to change line depths if used more than once.  
**xpos:** the \_x postion of your line.  
**ystart:** the \_y starting postion of your line.  
**thick:** how thick you want your line.  
**height:** obviously the height of your line.  
**color:** the color of your line in HEX format, but remember that Flash needs “0x” before the actual HEX, so refer to what I did above!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2002, 6:23pm UTC](https://forum.kirupa.com/t/draw-a-box/5101/12 "2002-09-01T18:23:37Z")

</div>

this is really helpful… didnt know much about drawing in Flash using actionscript… will be very useful!

Peace

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2002, 6:26pm UTC](https://forum.kirupa.com/t/draw-a-box/5101/13 "2002-09-01T18:26:49Z")

</div>

the code above is just for flash mx? i only have flash 5… I’ll check out the “scale” idea though…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2002, 11:40pm UTC](https://forum.kirupa.com/t/draw-a-box/5101/14 "2002-09-01T23:40:37Z")

</div>

dan4885\>\> how would I go about using that code, but instead of the line appearing, have it appear as though it is being drawn?

Peace

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 2, 2002, 6:43am UTC](https://forum.kirupa.com/t/draw-a-box/5101/15 "2002-09-02T06:43:00Z")

</div>

heres some drawing code…

```php
_root.createEmptyMovieClip("blank",0);
_root.blank.lineStyle(1, 0x000000);
_root.colourVar =0x000000;
_root.sizeVar = 1;
_root.onMouseDown = function() {
	_root.blank.moveTo(_root._xmouse, _root._ymouse);
	_root.onMouseMove = function() {		
		_root.blank.lineTo(_root._xmouse, _root._ymouse);
	};
};
_root.onMouseUp = function(){
	_root.onMouseMove = null;
}

```

Hope that helps…though im not dan…hehe 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 2, 2002, 11:08am UTC](https://forum.kirupa.com/t/draw-a-box/5101/16 "2002-09-02T11:08:02Z")

</div>

Finkman\>\> Try it, tell me if you have any trouble with it.  
Ryall\>\> Just break the path into several little pieces. Not too difficult.  
Bezzer\>\> Nice, but still MX… 🙂

pom :asian:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 2, 2002, 11:48am UTC](https://forum.kirupa.com/t/draw-a-box/5101/17 "2002-09-02T11:48:13Z")

</div>

yeah mx and api is good 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 3, 2002, 10:55pm UTC](https://forum.kirupa.com/t/draw-a-box/5101/18 "2002-09-03T22:55:46Z")

</div>

thanks for the info guys!

Peace

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 10, 2003, 10:17pm UTC](https://forum.kirupa.com/t/draw-a-box/5101/19 "2003-04-10T22:17:27Z")

</div>

HI Guys  
i’ve tried everything that I know and help stuff but The Line doesn’t appear!

What should I do?
