Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
121 lines (96 sloc) 2.72 KB
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class Timeline extends Sprite
{
private var bar:Sprite = new Sprite();
private var timeline_width:int = 0;
private var select:Sprite = new Sprite();
public var cur_pos:Number = 0;
public function Timeline(w:int = 473, pos:Number = 0):void
{
this.timeline_width = w;
this.cur_pos = pos;
this.addEventListener(Event.ADDED_TO_STAGE, this.addedToStage);
}
private function addedToStage(e:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, this.addedToStage);
this.draw();
addChild(this.bar);
with (this.select.graphics) {
beginFill(0xFFFFFF);
drawRect(0, 10, 1, 10);
endFill();
}
this.select.x = 10;
addChild(this.select);
this.addEventListener(MouseEvent.CLICK, mouseClick);
this.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
this.addEventListener(MouseEvent.MOUSE_OUT, mouseLeave);
}
private function mouseClick(e:MouseEvent):void
{
var xx = e.stageX - 20;
if (xx < 10)
xx = 0;
else if (xx > this.timeline_width + 10)
xx = this.timeline_width;
xx = xx / this.timeline_width;
if (xx > 1) xx = 1;
this.updateTimeline(xx);
dispatchEvent(new Event('SCENE_CHANGE'));
}
private function mouseMove(e:MouseEvent):void
{
this.select.x = e.stageX - 10;
if (this.select.x < 10)
this.select.x = 10;
else if (this.select.x > this.timeline_width + 10)
this.select.x = this.timeline_width + 10;
}
private function mouseLeave(e:MouseEvent):void
{
if (e.stageY > 35)
this.select.x = this.timeline_width * cur_pos + 10;
}
public function updateTimeline(pos:Number):void
{
this.cur_pos = pos;
this.select.x = this.timeline_width * cur_pos + 10;
this.draw();
}
private function draw():void
{
with (this.bar.graphics) {
clear();
beginFill(0x172322, .75);
drawRoundRect(0, 0, this.timeline_width + 20, 30, 15, 15);
endFill();
}
for (var i = 0; i < this.timeline_width * cur_pos; i++) {
with (this.bar.graphics) {
if (i % 2 == 0)
beginFill(0xF8E540);
else
beginFill(0xDFCA09);
drawRect(i + 10, 10, 1, 10);
endFill();
}
}
for (var i = 0; i < this.timeline_width - (this.timeline_width * cur_pos); i++) {
with (this.bar.graphics) {
if (i % 2 == 0)
beginFill(0x444444, .9);
else
beginFill(0x333333, .9);
drawRect((this.timeline_width * cur_pos) + i + 10, 10, 1, 10);
endFill();
}
}
}
}
}