PDA

View Full Version : Attaching to a Path using Actionscript



Malkav
06-05-2006, 11:00 AM
I've got some buttons that I've generated in actionscript, and now I need to attach them to a path. Can anybody help me?

NTD
06-05-2006, 01:18 PM
Hi,

What kind of path and how are the buttons generated? Post a code sample.

Malkav
06-05-2006, 02:44 PM
Hi,

What kind of path and how are the buttons generated? Post a code sample.

The path is a curved line, at the moment it's a motion guide with a box tweened to move along it. The buttons are generated in a for loop,



for &#40;c=0;c<totalNodes;c++&#41;
&#123;
aNode&#91;c&#93; = rootNode.childNodes&#91;c&#93;;
nodeButton&#91;c&#93; = new MovieClip&#40;&#41;;
nodeButton&#91;c&#93; = _root.createEmptyMovieClip&#40;"nodeButton"+c,2+c&#41;;
nodeButton&#91;c&#93;._x = 100;
nodeButton&#91;c&#93;._y = 40+&#40;c*25&#41;;

nodeButton&#91;c&#93;.lineStyle&#40;0,0x000000,100&#41;;
nodeButton&#91;c&#93;.beginFill&#40;0xFF0000,100&#41;;

nodeButton&#91;c&#93;.lineTo&#40;400,0&#41;;
nodeButton&#91;c&#93;.lineTo&#40;400,22&#41;;
nodeButton&#91;c&#93;.lineTo&#40;0,22&#41;;
nodeButton&#91;c&#93;.endFill&#40;&#41;;

txtField = new TextField&#40;&#41;;
txtField = nodeButton&#91;c&#93;.createTextField&#40;"txtField",2+c,0,0,400,22&#41;;
txtField.text = aNode&#91;c&#93;.attributes.Parentterm;
txtField.textColor = black;
dataField = new TextField&#40;&#41;;
dataField = nodeButton&#91;c&#93;.createTextField&#40;"dataField",3+c,300,0,400,22&#41;;
dataField.text = aNode&#91;c&#93;.attributes.conceptid1;
dataField.textColor = black;

nodeButton&#91;c&#93;.onRelease = function&#40;&#41;
&#123;
changeNode&#40;this.dataField.text&#41;;
&#125;

&#125;

NTD
06-10-2006, 09:49 PM
Hi,

If you know the coordinates of the line, find the _x and _y coordinates on that line of where you want the buttons placed. It would be easier to manipulate if the textfields were created inside a movieclip, but you can hard code the textfield positions.

Something like this could be achieved with some advanced Actionscript. You can use Math.sin and Math.cos to create a circular rotation from a center point. I made a curved scroller that employed this method some time ago but you need a pretty good understanding of OOP and Actionscript to understand what is going on.


var s = _root.createEmptyMovieClip&#40;"scroller", 10&#41;;
//set scrolltrack position
s._x = 250;
s._y = 200;
//scrolltrack angle controls length....3.6 = circle
s.maxAngle = 1.5;
s.minAngle = -1.5;
//scrolltrack radius
s.r = 150;
s.lineStyle&#40;3, 0x8888FF&#41;;
//draw scrolltrack
s.moveTo&#40;Math.cos&#40;s.minAngle&#41;*s.r, Math.sin&#40;s.minAngle&#41;*s.r&#41;;
for &#40;var i = s.minAngle; i<=s.maxAngle; i += .05&#41; &#123;
s.lineTo&#40;Math.cos&#40;i&#41;*s.r, Math.sin&#40;i&#41;*s.r&#41;;
&#125;


I'm not going to post the entire code as it will be ultra confusing but the above demonstrates how to caculate a position on an arc with a specified radius and center point.

hope it helps
NTD