We saw in the last article as a segment move with the motion applied to Actionscript 3.0.
I know, is pretty boring and simple but it is necessary to first understand the basics of what we will see in the future.
Now it is time to move on and then see how to move a pair of segments by trigonometry laws.
We will see that the rotation of the first leg means that the second segment remains stuck at the end of the first.
Not only that, we will see that the second segment will move a motion in relation to first.
Using two instances of the same MovieClip we saw in the first example and two instances of the component Slider.
The code I used:
Code:import fl.controls.SliderDirection; import fl.events.SliderEvent; slider_1.direction=SliderDirection.VERTICAL; slider_1.x=500; slider_1.y=350; slider_1.rotation=270; slider_1.minimum=0; slider_1.maximum=180; slider_1.value=90; segment_1_mc.rotation=slider_1.value; slider_1.addEventListener(SliderEvent.THUMB_DRAG,onChange); slider_2.direction=SliderDirection.VERTICAL; slider_2.x=530; slider_2.y=slider_1.y; slider_2.rotation=270; slider_2.minimum=0; slider_2.maximum=180; slider_2.value=90; segment_2_mc.rotation=slider_2.value; slider_2.addEventListener(SliderEvent.THUMB_DRAG,onChange); function onChange(evt:SliderEvent):void { segment_1_mc.rotation=slider_1.value; segment_2_mc.rotation=slider_2.value; var radians:Number=segment_1_mc.rotation*Math.PI/180; segment_2_mc.x=segment_1_mc.x+Math.cos(radians)*170; segment_2_mc.y=segment_1_mc.y+Math.sin(radians)*170; } var evt:SliderEvent; onChange(evt);Compared to the first example, there is a simple law of trigonometry.
PS: 170 is the distance between the two anchors of the segments.
Source files:
>
Bookmarks