import mx.utils.Delegate;
import mx.transitions.Tween;
import mx.transitions.easing.Regular;
class Window {
var width:Number;
var height:Number;
var home:MovieClip;
var im:MovieClip;
function Window(home:MovieClip,width:Number, height:Number) {
this.width = width;
this.height = height;
this.home = home;
}
public function draw(x:Number,y:Number,params:Object):Void{
var num:Number = home.getNextHighestDepth();
this.im = this.home.attachMovie("window","customWindow"+num,num);
this.im._y = y;
this.im._x = x;
this.im.bar._width = this.width;
if(params.showbar == false) this.im.bar._visible = false;
this.im.content._width = this.width;
this.im.content._height = this.height;
if(params.draggable != false){
this.im.bar.onPress = Delegate.create (this, startDrag);
this.im.bar.onRelease = Delegate.create(this,stopDrag);
this.im.bar.onReleaseOutside = Delegate.create(this,stopDrag);
}
this.im.content.onPress = Delegate.create (this, top);
if((params.forceDrag == true && params.showbar == false) || (params.allDraggable == true)){
this.im.content.onPress = Delegate.create (this, startDrag);
this.im.content.onRelease = Delegate.create(this,stopDrag);
this.im.content.onReleaseOutside = Delegate.create(this,stopDrag);
}
}
private function top():Void{
this.im.swapDepths(this.home.getNextHighestDepth());
}
private function startDrag():Void{
this.setProperty(this.im.content,"_alpha", 25, .5);
this.top();
this.im.startDrag(false);
}
private function stopDrag():Void{
this.setProperty(this.im.content,"_alpha", 100, .5);
this.im.stopDrag();
}
private function setProperty(target:MovieClip,property:String,value:Number,time:Number):Void{
var set:Tween = new Tween(target, property, Regular.easeOut, target[property], value, time, true);
}
public function get xny():Object{
return {x : this.im._x, y : this.im._y};
}
public function addContent(add:MovieClip):Void{
//todo
}
}