PDA

View Full Version : draw a box?



finkman
August 31st, 2002, 06:56 PM
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.

Ryall
August 31st, 2002, 10:17 PM
you want to draw a lint 20px by x pixels thick? or you want to draw a box 20px wide by x pixels high??

finkman
September 1st, 2002, 04:23 AM
a little illustration.. =)

20px
---
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | x px
| |
| |
| |
| |
| |
| |
| |
---


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

Bezzer
September 1st, 2002, 04:31 AM
ok do this on the first frame of a new movie...


_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 :)

Ryall
September 1st, 2002, 04:31 AM
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.

Bezzer
September 1st, 2002, 04:34 AM
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 :)

telekinesis
September 1st, 2002, 05:15 AM
Here is what you asked for, a function using a Drawing API Method:


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:

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!

Bezzer
September 1st, 2002, 06:53 AM
isn't that what i said? :) hehe

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

pom
September 1st, 2002, 09:40 AM
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:

pom
September 1st, 2002, 09:45 AM
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:

telekinesis
September 1st, 2002, 01:52 PM
I hate forgetting things, so here is the edited function:

Place this on your root timeline:

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:

_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!

Ryall
September 1st, 2002, 02:23 PM
this is really helpful... didnt know much about drawing in Flash using actionscript... will be very useful!

Peace

finkman
September 1st, 2002, 02:26 PM
the code above is just for flash mx? i only have flash 5.. I'll check out the "scale" idea though..

Ryall
September 1st, 2002, 07:40 PM
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

Bezzer
September 2nd, 2002, 02:43 AM
heres some drawing code...
_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 :)

pom
September 2nd, 2002, 07:08 AM
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:

Bezzer
September 2nd, 2002, 07:48 AM
yeah mx and api is good :)

Ryall
September 3rd, 2002, 06:55 PM
thanks for the info guys!

Peace

Alex_own
April 10th, 2003, 06:17 PM
HI Guys
i've tried everything that I know and help stuff but The Line doesn't appear!

What should I do?