package{
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.NativeWindowInitOptions;
import flash.display.NativeWindow;
import flash.display.Screen;
import flash.events.*;
import flash.geom.Point;
import flash.geom.Rectangle;
public class ControlWindow extends Sprite{
private var window:NativeWindow;
private var targetPoint:Point = new Point(300,100);
//flash IDE에 만들어져 있는 무비클립 참조용.
public var btnUp:Sprite;
public var btnDown:Sprite;
public var btnLeft:Sprite;
public var btnRight:Sprite;
public function ControlWindow(){
//화면 중앙에 컨트롤 윈도우 위치시키기.
var screenBound:Rectangle=Screen.mainScreen.bounds;
stage.nativeWindow.x = int(screenBound.width-stage.nativeWindow.width)/2;
stage.nativeWindow.y = int(screenBound.height-stage.nativeWindow.height)/2;
window = createWindow(); //조종될 새 윈도우 만들기 함수 호출
btnUp.addEventListener(MouseEvent.CLICK, moveWin);
btnDown.addEventListener(MouseEvent.CLICK, moveWin);
btnLeft.addEventListener(MouseEvent.CLICK, moveWin);
btnRight.addEventListener(MouseEvent.CLICK, moveWin);
}
private function moveWin(e:MouseEvent){
switch(e.target.name){
case "btnUp": targetPoint.y -= 50; break;
case "btnDown": targetPoint.y += 50; break;
case "btnLeft": targetPoint.x -= 50; break;
case "btnRight": targetPoint.x += 50; break;
}
}
private function createWindow():NativeWindow{
var windowOption:NativeWindowInitOptions=new NativeWindowInitOptions();
var window:NativeWindow=new NativeWindow(windowOption);
window.x=300, window.y=300;
window.width=400, window.height=100;
window.activate();
window.stage.addEventListener(Event.ENTER_FRAME, windowMove);
return window;
}
private function windowMove(e:Event){ //매 프레임 실행
window.x += 0.2 * (targetPoint.x-window.x);
window.y += 0.2 * (targetPoint.y-window.y);
}
}
}
|