topical media & game development
animation-ch14-TwoSegmentDrag.ax
animation-ch14-TwoSegmentDrag.ax
[swf]
[flash]
flex
package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
public class @ax-animation-ch14-TwoSegmentDrag extends Sprite
{
private var segment0:animation_ch14_Segment;
private var segment1:animation_ch14_Segment;
public function @ax-animation-ch14-TwoSegmentDrag()
{
init();
}
private function init():void
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
segment0 = new animation_ch14_Segment(100, 20);
addChild(segment0);
segment1 = new animation_ch14_Segment(100, 20);
addChild(segment1);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):void
{
drag(segment0, mouseX, mouseY);
drag(segment1, segment0.x, segment0.y);
}
private function drag(segment:animation_ch14_Segment, xpos:Number, ypos:Number):void
{
var dx:Number = xpos - segment.x;
var dy:Number = ypos - segment.y;
var angle:Number = Math.atan2(dy, dx);
segment.rotation = angle * 180 / Math.PI;
var w:Number = segment.getPin().x - segment.x;
var h:Number = segment.getPin().y - segment.y;
segment.x = xpos - w;
segment.y = ypos - h;
}
}
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.