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?
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 (c=0;c<totalNodes;c++)
{
aNode[c] = rootNode.childNodes[c];
nodeButton[c] = new MovieClip();
nodeButton[c] = _root.createEmptyMovieClip("nodeButton"+c,2+c);
nodeButton[c]._x = 100;
nodeButton[c]._y = 40+(c*25);
nodeButton[c].lineStyle(0,0x000000,100);
nodeButton[c].beginFill(0xFF0000,100);
nodeButton[c].lineTo(400,0);
nodeButton[c].lineTo(400,22);
nodeButton[c].lineTo(0,22);
nodeButton[c].endFill();
txtField = new TextField();
txtField = nodeButton[c].createTextField("txtField",2+c,0,0,400,22);
txtField.text = aNode[c].attributes.Parentterm;
txtField.textColor = black;
dataField = new TextField();
dataField = nodeButton[c].createTextField("dataField",3+c,300,0,400,22);
dataField.text = aNode[c].attributes.conceptid1;
dataField.textColor = black;
nodeButton[c].onRelease = function()
{
changeNode(this.dataField.text);
}
}
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("scroller", 10);
//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(3, 0x8888FF);
//draw scrolltrack
s.moveTo(Math.cos(s.minAngle)*s.r, Math.sin(s.minAngle)*s.r);
for (var i = s.minAngle; i<=s.maxAngle; i += .05) {
s.lineTo(Math.cos(i)*s.r, Math.sin(i)*s.r);
}
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
Powered by vBulletin™ Version 4.1.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.