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.
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
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; };
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.
I hope you can help out with an answer asap.
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.
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?
Hi, Yes they are going to drag and draw the line between the 2 axes.
Don't see what you're looking for? Try a search.
|