无论新手还是高手,看完后请指导! 无论是flash版,还是AIR版的,均是使用flash cs3进行编写的
flash版窗体系统demo观看地址:http://www.xiaos8.com/uploads/flash/window.swf AIR版窗体系统demo下载地址:http://www.xiaos8.com/uploads/flash/window.rar
有兴趣的朋友看看,多提提意见,由于美工是俺操刀的,因此画面难看了点,请多包涵
demo版本所展示的部分功能: 1、创建窗口 2、设置窗口宽高,标题 3、拖拽边缘缩放窗口,拖拽窗口 4、双击顶端的标题栏,最大化和缩放 5、实现不同的窗口机制 等等………………
窗体系统结构:
core核心包结构初略讲解: IWindow接口:定义所有窗口,并且Window实现了该接口 Module类:模块基类 PopModule类:弹出型环境类,继承Module PopWindow类:弹出型窗口,继承Window Window类:窗口基类 WindowEvent类:窗口事件类 WindowsManager类:窗口管理基类
core核心包实现讲解: 凡是flash cs3中继承Module的元件,都可以直接在元件的第一帧撰写代码,并且在编译的过程中会自动把代码编译出来并继承Module类,在第一帧所拽写的代码可以通过实例化后来访问,比如下面贴出的"控制台源码"就是如此写的 如果需要提供特殊环境等,可以继承Module撰写,比如PopModule,控制台的父类就是PopModule,在控制台的源码中,我们可以看得到他直接访问了window属性,得到的就是控制台所在的窗口对象 Window类实现了基本窗口操作,比如拖拽,关闭,显示等,与WindowManager是配套使用 如果需要更复杂的窗口,可以继承Window类撰写,比如PopWindow,FixedWindow类的父类就是PopWindow,在FixedWindow中,我们只需要把PopWindow的状态和模式定死在window和fixed就可以了,而PopWindow本来就是一个普通的窗口,因此创建Create窗口的时候,直接使用PopWindow即可创建一个普通的窗口,在PopWindow中,默认窗口的状态和模式都为window
由于该窗体系统是公司项目需要所开发的,因此无法开源,但demo中所使用的主要代码如下:
//文档类 package code{ import flash.display.Sprite; import flash.events.Event; import code.core.*; import code.windows.*; public class Index extends Sprite{ private var windows:WindowsManager = new WindowsManager; public function Index(){ stage.scaleMode = "noScale"; stage.align = "TL"; stage.showDefaultContextMenu = false; stage.addEventListener(Event.RESIZE,auto); addChild(windows); //AIR部分窗口最大化 // stage.nativeWindow.maximize(); init(); } //初始化 private function init():void{ //实例化窗口后即可,操作都在内部进行 new FixedWindow(new Console); //AIR部分关闭按钮的侦听 // new FixedWindow(new Console).addEventListener(WindowEvent.WINDOW_CLOSE,onWindowClose); auto(); } // //关闭 AIR部分 关闭窗口 // private function onWindowClose(e:WindowEvent):void{ // stage.nativeWindow.close(); // } //重排 private function auto(e:Object = null):void{ } } }
//控制台源码 继承PopModule import code.core.PopWindow;
//因为PopModule已经实现了初始化完毕后自动执行createComplete,因此咱们只要设置该值,就可以得到控制台初始化完毕的事件 createComplete = init;
function init():void{ show(); window.title = "控制台"; window.x = stage.stageWidth - window.width; window.y = stage.stageHeight - window.height; }
titleText.defaultTextFormat = new TextFormat("宋体",12,0); titleText.text = "未命名窗口"; widthText.text = "375"; heightText.text = "160";
createButton.addEventListener(MouseEvent.CLICK,onClick);
function onClick(e:MouseEvent):void{ var create:Create = new Create; create.addChild(drawPanel.content); var pop:PopWindow = new PopWindow(create); pop.windowWidth = Number(widthText.text); pop.windowHeight = Number(heightText.text); pop.title = titleText.text; pop.show(); }
//简单画板源码 package code.element{ import flash.display.Sprite; import flash.events.MouseEvent; public class DrawPanel extends Sprite{ private var _content:Sprite; public function DrawPanel(){ init(); } //初始化 private function init():void{ newDrag(); drawArea.addEventListener(MouseEvent.MOUSE_DOWN,onDrawAreaMouseDown); } //新的画板 private function newDrag():void{ if(_content) removeChild(_content); _content = new Sprite; _content.graphics.lineStyle(0); addChild(_content); } //鼠标按下事件 private function onDrawAreaMouseDown(e:MouseEvent):void{ stage.addEventListener(MouseEvent.MOUSE_UP,onStageMouseUp); drawArea.addEventListener(MouseEvent.MOUSE_MOVE,onDrawAreaMouseMove); _content.graphics.moveTo(e.localX,e.localY); } //鼠标弹起事件 private function onStageMouseUp(e:MouseEvent):void{ stage.removeEventListener(MouseEvent.MOUSE_UP,onStageMouseUp); drawArea.removeEventListener(MouseEvent.MOUSE_MOVE,onDrawAreaMouseMove); } //鼠标移动事件 private function onDrawAreaMouseMove(e:MouseEvent):void{ _content.graphics.lineTo(e.localX,e.localY); e.updateAfterEvent(); } //获取内容 public function get content():Sprite{ var reSpr:Sprite = _content; newDrag(); return reSpr; } } }
//控制台的基类固定窗口类 package code.windows{ import code.core.PopWindow; import code.core.Module; public class FixedWindow extends PopWindow{ public function FixedWindow(_module:Module):void{ super(_module); init(); } //初始化 private function init():void{ state = "window"; mode = "fixed"; } } } |