⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 panel0.as

📁 flash编程实例
💻 AS
字号:
class Scene.Manage.Panels.Group0.Panel0 extends MovieClip {
	//
	private var BaseBar:MovieClip;
	private var PastData:String = "";
	private var onResult:Function;
	private var NodeReferance:Object;
	private var SubNodeReferance:Object;
	private var AppTree:MovieClip;
	//Button referances
	private var load_btn:MovieClip;
	private var view_btn:MovieClip;
	private var unload_btn:MovieClip;
	private var activated:Boolean = false;
	
	function Panel0() {
		_global.Panel0 = this;
		//Attach all UI
		attachMovie("Panel0_BaseBar", "BaseBar", 0);
		attachMovie("Tree", "AppTree", 1);
		//
		AppTree.setSize(550, 400);
		//
		BaseBar._x = 10;
		BaseBar.attachMovie("ComboBox", "combo", BaseBar.getNextHighestDepth());
		//Create buttons
		load_btn = BaseBar.attachMovie("Button", "load_btn", BaseBar.getNextHighestDepth());
		view_btn = BaseBar.attachMovie("Button", "view_btn", BaseBar.getNextHighestDepth());
		unload_btn = BaseBar.attachMovie("Button", "unload_btn", BaseBar.getNextHighestDepth());
		//Register Events
		load_btn.addEventListener("click", this);
		view_btn.addEventListener("click", this);
		unload_btn.addEventListener("click", this);
		//Work The sub items
		BaseBar.combo._x = 174;
		BaseBar.combo._y = 4;
		load_btn._y = 3;
		load_btn.setSize(60, 24);
		load_btn.label = "Load";
		//
		view_btn.label = "View";
		view_btn._y = 3;
		view_btn._x = 3;
		view_btn.setSize(70, 24);
		//
		unload_btn.label = "Unload";
		unload_btn._y = 3;
		unload_btn._x = 84;
		unload_btn.setSize(80, 24);
		//
		NodeReferance = new Object();
		SubNodeReferance = new Object();
		//
		AppTree._x = 10;
		AppTree._y = 10;
		//
		setInterval(doUpdate, 300, this);
	}
	function click(evt){
		if(evt.target == load_btn){
			doLoad();
		}else if(evt.target == view_btn){
			doView();
		}else if(evt.target == unload_btn){
			doUnload();
		}
	}
	function doUpdate(p:MovieClip){
		p.loadApplications();
	}
	function workCombo(){
		BaseBar.combo.editable = true;
		getInstApp();
	}
	//Panel Skeliton methods
	public function activate() {
		activated = true;
		//Called when this panel is the selected tab
		loadApplications();
		BaseBar.combo.editable = true;
		getInstApp();
	}
	public function deactivate() {
		//Called when this panel is no longer selected
		activated = false;
	}
	//Functionality for this page
	function loadApplications() {
		_global.Connection.Net.call("getActiveInstances", new onGetActiveInstances(this));
	}
	function onGetActiveInstances(mc) {
		onResult = function (result) {
			mc.workActiveApps(result);
		};
	}
	function ShiftApplication(app, instance){
		//
		var appNode = NodeReferance[app];
		//
		if(AppTree.getIsBranch(appNode) == true){
			//Further processing
			if(instance == "/_definst_"){
				//Handle this differently
			}else{
				RemoveFromSubNode(app, instance);
			}
		}else{
			//Remove the entire node
			AppTree.removeTreeNodeAt(AppTree.getDisplayIndex(appNode));
			//
			delete SubNodeReferance[app];
			delete NodeReferance[app];
		}
	}
	function RemoveFromSubNode(app, instance){
		//
		var appNode = NodeReferance[app];
		//
		var instNode = SubNodeReferance[app][instance];
		//To make this work we have to remove the node from the tree, re-form it and then decide
		//weather to re-add it to the tree
		//
		//Remove Node
		var index = AppTree.getDisplayIndex(appNode);
		AppTree.removeTreeNodeAt(index);
		//Find the node and remove it
		for(var i=0;i<appNode.childNodes.length;i++){
			if(appNode.childNodes[i] == instNode){
				appNode.childNodes[i].removeNode();
				//
				delete SubNodeReferance[app][instance];
				//
				break;
			}
		}
		//
		if(appNode.childNodes.length == 0){
			//What we have done has cleared the node entirly and it has no more children
			//do a small test
			if(appNode.attributes.data == "_definst_"){
				//Still counts
				AppTree.addTreeNodeAt(index, appNode);
			}else{
				//Do not add the node back on
				delete SubNodeReferance[app];
				delete NodeReferance[app];
			}
		}else{
			AppTree.addTreeNodeAt(index, appNode);
		}
		//
	}
	function workActiveApps(data) {
		if (data.level == "status") {
			//compare the to original objects and get rid of the old ones
			var apps = data.data;
			var AppList:Array = new Array();
			var tempHis:String = "";
			var oldList = PastData.split(",");
			var count = 0;
			for(var i in apps){
				if (i != "__proto__") {
					var appString:String = apps[i];
					count++;
					tempHis += appString+",";
					if(PastData.indexOf(appString+",") == -1){
						//This application wasent there the last time so we must put it in this render
						var appName = appString.substr(0, appString.indexOf("/"));
						var subname = appString.substr(appString.indexOf("/"), appString.length);
						//Append this data
						AppList.push({application:appName, instance:subname});
					}
				}
			}
			if(activated){
				_root.main.TabBar.replaceItemAt(0, {label:"Applications:"+count, icon:"panel1_icon"});
			}
			PastData = tempHis;
			//Remove useless old nodes - This is very anoying to do :( grrrrrr
			for(var i=0;i<oldList.length;i++){
				var appString:String = oldList[i];
				if(PastData.indexOf(appString) == -1){
					//Woah its gone, clear it boyo
					var appName = appString.substr(0, appString.indexOf("/"));
					var subname = appString.substr(appString.indexOf("/"), appString.length);
					//
					ShiftApplication(appName, subname);
				}
			}
			//
			for(var i=0;i<AppList.length;i++){
				var item = AppList[i];
				if(NodeReferance[item.application]){
					//yes a node, append
					if(item.instance != "/_definst_"){
						if(!SubNodeReferance[item.application])
						{
							SubNodeReferance[item.application] = new Object();
						}
						SubNodeReferance[item.application][item.instance] = NodeReferance[item.application].addTreeNode(item.instance, item.application);
					}else{
						NodeReferance[item.application].attributes.data = "_definst_";
					}
				}else{
					NodeReferance[item.application] = AppTree.addTreeNode(item.application);
					if(item.instance != "/_definst_"){
						//
						if(!SubNodeReferance[item.application])
						{
							SubNodeReferance[item.application] = new Object();
						}
						//
						SubNodeReferance[item.application][item.instance] = NodeReferance[item.application].addTreeNode(item.instance, item.application);
					}else{
						NodeReferance[item.application].attributes.data = "_definst_";
					}
				}
			}
		}
	}
	function getInstApp(){
		var p = this;
		var instAppResult = function(){
			this.onResult = function(res){
				p.BaseBar.combo.dataProvider = res.data;
			}
		}
		_global.Connection.Net.call("getApps",new instAppResult());
	}
	//Base bar methods
	public function doLoad(){
		_global.Connection.Net.call("reloadApp", null, BaseBar.combo.value);
	}
	public function doReload(){
		var app = selectedApplication;
		_global.Connection.Net.call("reloadApp", null, app);
	}
	public function doUnload(){
		var app = selectedApplication;
		_global.Connection.Net.call("unloadApp", null, app);
	}
	public function doView(){
		var s = selectedApplication;
		if(s != false){
			//Set the selected application
			_global.selectedApplication = s;
			_global.Connection.SelectedApplication = s;
			//Convert the UI to app explore mode, _parent is the ScreenManager
			_parent.setGroup(1);
			_parent.selectedIndex = 0;
			_parent._parent.tab1Button0._visible = _parent._parent.tab1Button1._visible = true;
			//
			_root.main.Light2.connect(_global.Connection.AppNet);
		}
	}
	public function get selectedApplication(){
		var sel = AppTree.selectedNode;
		var branch = AppTree.getIsBranch(sel);
		//
		if(branch == true){
			if(sel.attributes.data){
				return checkExistance(sel.attributes.label+sel.attributes.data);
			}else{
				return checkExistance(sel.attributes.label+"/_definst_");
			}
		}else{
			if(sel.attributes.data){
				return checkExistance(sel.attributes.label+"/"+sel.attributes.data);
			}else{
				return checkExistance(sel.attributes.label+"/_definst_");
			}
		}
	}
	private function checkExistance(p:String)
	{
		if(PastData.indexOf(p+",") == -1){
			return false;
		}else{
			return p;
		}
	}
	//UI Render
	public function setSize(w:Number, h:Number) {
		BaseBar._y = h-40;
		var bw = w-20;
		BaseBar.combo.setSize(w-260, 22);
		BaseBar.combo.combo_shadow._width = bw-264;
		BaseBar.load_shadow._x = bw-56;
		BaseBar.load_btn._x = bw-53;
		AppTree.setSize(w-20, h-70);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -