Groups | Blog | Home
all groups > flash actionscript > june 2005 >

flash actionscript : How to do this in flash?? Please help...


gss266
6/21/2005 7:53:29 PM
Hi,

I have an X and Y axes and I am trying to give the user the interactive option
of drawing a line with either a posive slope or a negative slope within the
axes to just show the relationship between x variable and Y variable. How can
this line be drawn dynamically?

Please help out.

Thanks in advance.

TimSymons
6/22/2005 7:19:36 PM
You can use the Drawing API.

var sample_mc = this.createEmptyMovieClip("theLine", 1);
sample_mc.lineStyle(5, 0xFF00FF, 100);
sample_mc.moveTo(200, 200);
sample_mc.lineTo(300, 300);

Check out the Help files on "lineStyle", "moveTo", "lineTo", "beginFill" and
others to get a good idea of what you can draw with AS. Also, do a search at
Macromedia.com for "draw api". There are a couple of other cool drawing
functions for arc and semi-circles that developers have written.

Tim
M_Brunken
6/22/2005 8:12:18 PM
yeah dude, use that drawing stuff, you can make the user draw a line by
himself, or even like a pen, just do like this code:

_root.onMouseDown = function() {
if (pressed != true) {
pressed = true;
_root.createEmptyMovieClip("line", _root.getNextHighestDepth());
_root.line.lineStyle(3, "0xFF0000");
// a red line
_root.line.moveTo(_root._xmouse, _root._ymouse);
}
};
_root.onMouseUp = function() {
_root.line.lineTo(_root._xmouse, _root._ymouse);
pressed = false;
};
gss266
6/30/2005 12:00:00 AM
Hi,

Thanks. I tried the above code. I have a couple of questions on that. Is it
possible to define the places where I want to draw this line. i.e If I have an
X and Y axis, is it possible for me to restrict drawing the line between these
2 axes and not outside in the work area? Also, is it possible to remove a line
which I dont want?

Please suggest.

Thanks.
gss266
7/1/2005 12:00:00 AM
I hope you can help out with an answer asap.

kglad
7/1/2005 12:00:00 AM
gss266
7/1/2005 7:19:28 PM
Thanks for the response. Well I just need the user to be restricted within the
spaces of the x-y axes. For example if X axis has 5 units and Y has 5, then
they shud not able to draw anything beyond the square of (0,0)(5,0) (0,5) and
(5,5). The line shud be withing this space and can be either direction. I hope
that is clear.
Also, is it possible to have an option of refreshing the file...i.e if user
draws a line he cannot undo it, is there a way to erase or refresh hiting a
button maybe...I am not sure...Please advice if possible.

Thanks.
kglad
7/2/2005 1:32:24 AM
that and more is possible. but you still haven't explained how a user is going
to "draw" a line.

are they going to drag the mouse across the graph area and create a line
segment? are they disignating two points in an input textfield? one point and
a slope? something else?
gss266
7/6/2005 12:00:00 AM
Hi,

Yes they are going to drag and draw the line between the 2 axes.

AddThis Social Bookmark Button