Показать сообщение отдельно
Старый 11.03.2012, 02:21
i.o. вне форума Посмотреть профиль Отправить личное сообщение для i.o. Найти все сообщения от i.o.
  № 5  
Ответить с цитированием
i.o.
 
Аватар для i.o.

Регистрация: Apr 2010
Адрес: Earth
Сообщений: 1,897
Особо извращенный вариант (просьба ногами не запинывать):
Код AS3:
public class ResourceProvider
{
	public function ResourceProvider()
	{
		// Init resource list
		this._resHashtable = new Object();
		this._resHashtable["resource001"] = new Bitmap();
		this._resHashtable["resource002"] = new Bitmap();
		this._resHashtable["resource003"] = new Bitmap();
		this._resHashtable["resource004"] = new Bitmap();
 
		this._resPtrRefs = new Dictionary(true);
 
		// Validate ptrs
		setInterval(this._validatePtrs, 1000);
	}
 
	private var _resHashtable : Object;
	private var _resPtrRefs : Dictionary;
 
	public function getResourcePointer( id:String ) : ResourcePointer 
	{
		if (!(id in this._resHashtable))
			return null;
 
		var ptr:ResourcePointer = new ResourcePointer(id, this);
		this._resPtrRefs[ptr] = true;
		return ptr;
	}
 
	internal function getResourceById( id:String ) : Object
	{
		return this._resHashtable[id] as Object;
	}
 
	private function _validatePtrs( ...args ) : void
	{
		var count:int = 0;
		for (var p:Object in this._resPtrRefs)
			count++;
 
		if (count == 0)
			this._destroy();
	}
 
	private function _destroy() : void
	{
		// TODO destroy here
	}
}
 
public class ResourcePointer
{
	public function ResourcePointer( id:String, provider:ResourceProvider )
	{
		this._id = id;
		this._provider = provider;
	}
 
	private var _id : String;
	private var _provider : ResourceProvider;
 
	public function getResource() : Object
	{
		return this._provider.getResourceById(this._id);
	}
}


Последний раз редактировалось i.o.; 11.03.2012 в 02:24.