Форум Flasher.ru
Ближайшие курсы в Школе RealTime
Список интенсивных курсов: [см.]  
  
Специальные предложения: [см.]  
  
 
Блоги Правила Справка Пользователи Календарь Поиск рулит! Сообщения за день Все разделы прочитаны
 

Вернуться   Форум Flasher.ru > Flash > ActionScript 3.0

Версия для печати  Отправить по электронной почте    « Предыдущая тема | Следующая тема »  
Опции темы Опции просмотра
 
Создать новую тему  
Старый 25.05.2007, 15:27
Фломастер вне форума Посмотреть профиль Отправить личное сообщение для Фломастер Найти все сообщения от Фломастер
  № 3  
Ответить с цитированием
Фломастер

Регистрация: Jun 2005
Сообщений: 104
вот мой класс

Код:
package {
	import flash.xml.XMLDocument;
	import flash.xml.XMLNode;
	import flash.xml.XMLNodeType;
	import flash.system.System;

	class XMLStructure {
		static var currentImage:Image = new Image();
		static var currentFolder:Folder = new Folder();
		static var input_xml = new XMLDocument();
		function XMLStructure(xml_document:String) {
			var nodeDepth = 0;
			XMLNode.prototype.nextNodeTab = function() {
			if (this.firstChild != null) {
			this.firstChild.attributes.tab = ++nodeDepth;
			return this.firstChild;
			}
			var n = this;
			while (n.nextSibling == null) {
			if (n.parentNode) {
			nodeDepth--;
			n = n.parentNode;
			} else {
			return null;
			}
			}
			n.nextSibling.attributes.tab = nodeDepth;
			return n.nextSibling;
			};
			XMLNode.prototype.nextNode = function() {
			if (this.firstChild != null) {
			//this.firstChild.attributes.tab = ++_root.nodeDepth;
			return this.firstChild;
			}
			var n = this;
			while (n.nextSibling == null) {
			if (n.parentNode) {
			//_root.nodeDepth--;
			n = n.parentNode;
			} else {
			return null;
			}
			}
			//n.nextSibling.attributes.tab = _root.nodeDepth;
			return n.nextSibling;
			};
			XMLNode.prototype.previousNode = function() {
			var n = this;
			if (n.previousSibling == null) {
			if (n.parentNode) {
			
			n = n.parentNode;
			return n;
			} else {
			return null;
			}
			}
			n = n.previousSibling;
			while (n.lastChild != null) {
			
			n=n.lastChild;
			}
			
			return n;
			};
			XMLNode.prototype.get_parentNode = function() {
			var n = this;
			return n.parentNode;
			};
			System.useCodePage = true;
			input_xml.ignoreWhite = true;//  было XMLDocument.prototype.ignoreWhite = true;
			input_xml.load(xml_document);
			//var intervalID:Number = setInterval(checkProgress, 1, input_xml);
			input_xml.onLoad = function(success) {
			//clearInterval(intervalID);
			//trace("intervalID: "+intervalID);
			if (success) {
			if (this.status != 0) {
			trace("xml - invalid");
			} else {
			trace("successfull");
			this.addAttributes();
			this.init();
			}
			} else {
			trace("error opening URL");
			}
			};
			input_xml.addAttributes = function() {
			var i = 0;
			var nod = this.firstChild;
			while (nod) {
			nod.attributes.ID = i++;
			nod = nod.nextNodeTab();
			}
			this.parseXML(this.firstChild);
			};
			input_xml.init = function() {
			var nod = input_xml.firstChild;
			while (nod.attributes.ID == 0) {
			nod = nod.nextNode();
			}
			if (nod == null) {
			trace("no images");
			return null;
			} else {
			currentFolder = nod.parentNode.attributes;
			while (nod.nodeName.toUpperCase() != "IMAGE") {
			nod = nod.nextSibling;
			if (nod == null) {
			trace("no images");
			return null;
			} else {
			currentFolder = nod.parentNode.attributes;
			}
			}
			currentImage = nod.attributes;
			return currentImage.name;
			}
			};
		}
		var checkProgress = function () {
		var bytesLoaded:Number = input_xml.getBytesLoaded();
		var bytesTotal:Number = input_xml.getBytesTotal();
		var percentLoaded:Number = Math.floor((bytesLoaded/bytesTotal)*100);
		if (isNaN(percentLoaded)) {
		return 0;
		} else {
		return percentLoaded;
		}
		};
		function nextImage() {
			var nod = input_xml.firstChild;
			while (nod.attributes.ID != currentImage.ID) {
				nod = nod.nextNode();
			}
			nod = nod.nextNode();
			if (nod == null) {
				trace("images ends");
				return null;
			} else {
				currentFolder = nod.parentNode.attributes;
				while (nod.nodeName.toUpperCase() != "IMAGE") {
					nod = nod.nextNode();
					if (nod == null) {
						trace("images ends");
						return null;
					} else {
						currentFolder = nod.parentNode.attributes;
					}
				}
				currentImage = nod.attributes;
				return currentImage.name;
			}
		}
		function previousImage() {
			var nod = input_xml.firstChild;
			while (nod.attributes.ID != currentImage.ID) {
				nod = nod.nextNode();
			}
			nod = nod.previousNode();
			if (nod == null) {
				trace("images ends");
				return null;
			} else {
				currentFolder = nod.parentNode.attributes;
				while (nod.nodeName.toUpperCase() != "IMAGE") {
					nod = nod.previousNode();
					if (nod == null) {
						trace("images ends");
						return null;
					} else {
						currentFolder = nod.parentNode.attributes;
					}
				}
				currentImage = nod.attributes;
				return currentImage.name;
			}
		}
		function get_currentImage() {
			return currentImage;
		}
		function set_currentImage(identificator:Number) {
			var nod = input_xml.firstChild;
			while (nod.attributes.ID != identificator) {
				nod = nod.nextNode();
			}
			if (nod == null) {
				trace("images ends");
				return null;
			} else {
				currentFolder = nod.parentNode.attributes;
				while (nod.nodeName.toUpperCase() != "IMAGE") {
					nod = nod.nextNode();
					if (nod == null) {
						trace("images ends");
						return null;
					} else {
						currentFolder = nod.parentNode.attributes;
					}
				}
				currentImage = nod.attributes;
				return currentImage.name;
			}
		}
	}
}

Создать новую тему   Часовой пояс GMT +4, время: 21:52.
Быстрый переход
  « Предыдущая тема | Следующая тема »  
Опции темы
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.


 


Часовой пояс GMT +4, время: 21:52.


Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.