/**
* Copyright frankz0424 ( http://wonderfl.net/user/frankz0424 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/j847
*/
// forked from actionscriptbible's Chapter 14 Example 3
package {
import flash.display.CapsStyle;
import flash.display.Sprite;
import flash.events.MouseEvent;
public class ch14ex3 extends Sprite {
protected const NUM_SEGMENTS:int = 10;
protected var segmentRotation:Number = 0;
protected var allSegments:Array;
public function ch14ex3() {
allSegments = new Array();
var segmentLength:Number = stage.stageWidth / NUM_SEGMENTS;
var segment:Sprite = this;
segment.y = stage.stageHeight/2;
for (var i:int = 0; i < NUM_SEGMENTS; i++) {
var childSegment:Sprite = makeSegment(segmentLength);
segment.addChild(childSegment);
childSegment.x = segmentLength;
allSegments.push(childSegment);
//every segment gets added as a child of the last one
segment = childSegment;
}
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
protected function onMouseMove(event:MouseEvent):void {
var segmentRotation:Number =
360/NUM_SEGMENTS * 2*((stage.mouseY / stage.stageHeight) - 0.5);
for each (var segment:Sprite in allSegments) {
//all rotation values are set to the same number,
//yet the line curls inward progressively!
//this is because every rotation affects all its children.
segment.rotation = segmentRotation;
}
}
protected function makeSegment(length:Number):Sprite {
var s:Sprite = new Sprite();
s.graphics.lineStyle(16, 0xc0c0c0, 1, false, null, CapsStyle.NONE);
s.graphics.lineTo(length, 0);
return s;
}
}
}