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.
you want to draw a lint 20px by x pixels thick? or you want to draw a box 20px wide by x pixels high??
a little illustration… =)
20px
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | x px
| |
| |
| |
| |
| |
| |
it’s a line, 20 px thick and x pixles high.
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
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.
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
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!
isn’t that what i said? hehe
I didin put the colour and stuff like that in though… but yeah close enough…
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:
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:
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!
this is really helpful… didnt know much about drawing in Flash using actionscript… will be very useful!
Peace
the code above is just for flash mx? i only have flash 5… I’ll check out the “scale” idea though…
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
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
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:
yeah mx and api is good
thanks for the info guys!
Peace
HI Guys
i’ve tried everything that I know and help stuff but The Line doesn’t appear!
What should I do?