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

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

Версия для печати  Отправить по электронной почте    « Предыдущая тема | Следующая тема »  
Опции темы Опции просмотра
 
Создать новую тему Ответ
Старый 06.05.2008, 19:48
Sneg вне форума Посмотреть профиль Отправить личное сообщение для Sneg Найти все сообщения от Sneg
  № 11  
Ответить с цитированием
Sneg
 
Аватар для Sneg

Регистрация: Oct 2005
Адрес: Russia, Moscow
Сообщений: 316
Отправить сообщение для Sneg с помощью ICQ
Тогда покажите код этого несчастного рендерера. А то гадать можно долго.

Старый 06.05.2008, 20:02
Borman2000 вне форума Посмотреть профиль Отправить личное сообщение для Borman2000 Найти все сообщения от Borman2000
  № 12  
Ответить с цитированием
Borman2000
 
Аватар для Borman2000

Регистрация: Dec 2006
Сообщений: 50
Отправить сообщение для Borman2000 с помощью ICQ
Код:
package com.Rating
{
		
	[Style(name="horizontalGap", type="Number", format="Length", inherit="no")]
	[Style(name="paddingLeft", type="Number", format="Length", inherit="no")]
	[Style(name="paddingTop", type="Number", format="Length", inherit="no")]
			
	[Event("change")]	
	public class VoteRenderer extends UIComponent implements IDataRenderer, IDropInListItemRenderer, IListItemRenderer
    {
		
 		public function VoteRenderer():void
		{
			//add the mouse move event listener so that we can update 
			//the display as the user moves out of the component capture both
			//rollout and mouse out to ensure proper display updating
			
				addEventListener(MouseEvent.MOUSE_OUT,handleMouseOut);
				addEventListener(MouseEvent.ROLL_OUT,handleMouseOut);
				
				//make sure we can get notified of the child events
				mouseChildren = true;
trace('VoteRenderer');
		}
		
		/**
		* Store the number of items to create. 
		**/
		private const itemCount:Number =5;
		
		private var contentWidth:Number=0;
		private var isResult:Boolean = false;
		public static var abc:Number = 0;
		
		
		/**
		* Data storage.
		**/
		private var _data:Object;
	
	    [Bindable("dataChange")]
	    [Inspectable(environment="none")]
	    public function get data():Object
	    {
			return _data;    	
	    }
	   
	    public function set data(value:Object):void
	    {	    	
    		 _data = value;
			
			try{
				if (_listData && _listData is DataGridListData)
	        	{
	            	this.value = _data[DataGridListData(_listData).dataField];
	        	}
	        	else
	        	{
	        		this.value = int(_listData.label);
	        	}
	        	
   			}
   			catch(e:Error){
   			}
   			
			dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));

	    }
	    
	    /**
	    * Storage for the listData property.
	    */
	    private var _listData:BaseListData;
	    [Bindable("dataChange")]
	    public function get listData():BaseListData
	    {
	      return _listData;
	    }
	    public function set listData(value:BaseListData):void
	    {
	      _listData = value;
	    }
		
		/**
		* An array of tooltips for the rating items
		**/
		[Bindable]
		[Inspectable]
		private var _tooltips:Array = null;
		public function set tooltips(value:Array):void
		{
			_tooltips = value;
			
		}
		public function get tooltips():Array
		{
			return _tooltips;
		}
		
		
		/**
		* the value of the rating
		**/
		[Bindable(event="change")]
		[Inspectable]
		private var _value:int = 0;
		public function set value(value:int):void
		{
			_value = value;
			selectItems(value);
			
			try{
				if (_listData && _listData is DataGridListData)
		        {
		           	_data[DataGridListData(_listData).dataField] = _value;
		        }
		        else
		        {
		        	_listData.label = _value.toString();
		        }
	        }
   			catch(e:Error){
   				
   			}
   				
			
			dispatchEvent(new Event("change"));
			
		}
		public function get value():int
		{
			return _value;
		}
		
		[Bindable]
		[Inspectable]
		private var _type:int;
		public function set type(value:int):void
		{
			_type = value;
		}
		
		public function get type():int
		{
			return _type;
			
		}
		
		[Bindable]
		[Inspectable]
		private var _outerRadius:Number=50;
		public function set outerRadius(value:Number):void
		{
			_outerRadius = value;
			updateChildren("outerRadius",value);
		}
		
		public function get outerRadius():Number
		{
			return _outerRadius;
			
		}
		
		[Bindable]
		[Inspectable]
		private var _innerRadius:Number=25;
		public function set innerRadius(value:Number):void
		{
			_innerRadius = value;
			updateChildren("innerRadius",value);
		}
		public function get innerRadius():Number
		{
			return _innerRadius;
		}
					
		[Bindable]
		[Inspectable]
		private var _points:Number=5;
		public function set points(value:Number):void
		{
			_points = value;
			updateChildren("points",value);
		}
		public function get points():Number
		{
			return _points;
		}
		
		[Bindable]
		[Inspectable]
		private var _angle:Number = 90;
		public function set angle(value:Number):void
		{
			_angle = value;
			updateChildren("angle",value);
		}
		public function get angle():Number
		{
			return _angle;
		}		

		/**
		 * Update the children if the property changes.
		 **/
		private function updateChildren(property:String, value:Number):void
		{
			for (var i:int = 0; i < itemCount; i++)
			{
				
				if (getChildByName(i.toString())){
					RatingItem(getChildByName(i.toString()))[property]=value;
				}
			}
		}

		/**
		* Add the star objects for rating and set thier properties and 
		* add the event listener for rollover and click
		**/
		//override protected function childrenCreated():void
		override protected function commitProperties():void
		{
			//use the horizontal Gap style for spacing between items
			var horizontalGap:Number = getStyle("horizontalGap");
			var paddingLeft:Number = getStyle("paddingLeft");
			var paddingTop:Number = getStyle("paddingTop");
			var lastX:Number = 0;

			if(type == 1){
				//create each item, set the properties, and add the listeners. 		   
				for (var i:int = 0; i < itemCount; i++)
				{
					var newItem = new RatingItem();
					newItem.id = (i).toString();
					newItem.name =(i).toString();
					
					//if the tooltips are set apply it to the primitive
					if (tooltips)
					{
						if (tooltips.length >(i-1)){
							newItem.toolTip = tooltips[i-1].toString();
						}
					}
												
					//set the default width and height
					newItem.width = 12;
					newItem.height = 12;
					addChild(newItem);
									
					if (lastX == 0)
					{
						newItem.x=paddingLeft;
					}	
					else
					{			
						newItem.x= ((12+horizontalGap)+lastX);
					}
	
					lastX = newItem.x;
	
					newItem.y= paddingTop;
					
					//set the inicial value based on this value
					if ((i-1) < value)
					{
						newItem.selected = true;
					}
	
					if(this.parentApplication.currentState != 'gridMyFiles'){
						newItem.addEventListener(MouseEvent.CLICK,handleItemClick,false,1);
						newItem.addEventListener(MouseEvent.ROLL_OVER,handleMouseRoll);
						newItem.addEventListener(MouseEvent.ROLL_OUT,handleMouseRoll);
					}
						
				}
			} else {
				if(type == 2){
					var newItem = new RadioButton;
					newItem.id = "0";
					newItem.name ="0";
					
					//set the default width and height
					newItem.width = 50;
					newItem.height = 15;
					newItem.groupName="vote";
					newItem.label = "YES";
					newItem.styleName = "voteRadioButton";
					newItem.x = 0;
					newItem.y = paddingTop;
					newItem.selected = "false";
					addChild(newItem);
					
					if(this.parentApplication.currentState != 'gridMyFiles'){
						newItem.addEventListener(MouseEvent.CLICK,handleItemClick,false,1);
						newItem.addEventListener(MouseEvent.ROLL_OVER,handleMouseRoll);
						newItem.addEventListener(MouseEvent.ROLL_OUT,handleMouseRoll);
					}
						
 					var newItem = new RadioButton;
					newItem.id = "1";
					newItem.name ="1";
					
					//set the default width and height
					newItem.width = 45;
					newItem.height = 15;
					newItem.groupName="vote";
					newItem.label = "NO";
					newItem.styleName = "voteRadioButton";
					newItem.x = 53;
					newItem.y = paddingTop;
					newItem.selected = "false";
					addChild(newItem);
					
					//set the inicial value based on this value
					if(this.parentApplication.currentState != 'gridMyFiles'){
						newItem.addEventListener(MouseEvent.CLICK,handleItemClick,false,1);
						newItem.addEventListener(MouseEvent.ROLL_OVER,handleMouseRoll);
						newItem.addEventListener(MouseEvent.ROLL_OUT,handleMouseRoll);
					}
				}	
			}
			
			width=newItem.x+horizontalGap;
			height = 12;
		}
						
		override protected function updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void
		{
												
			super.updateDisplayList(unscaledWidth,unscaledHeight);
			
			//draw a transparent background so we can get the 
			//rollout/over event on the ui object in not doing 
			//this we'll get flashing when moving between items
			graphics.lineStyle(0,0xFFFFFF,0);
			graphics.beginFill(0xFFFFFF,0);
			graphics.drawRect(0,0,unscaledWidth,unscaledHeight);
			graphics.endFill();
			
						
		}
		
		//do the selection based on passed value
		private function selectItems(value:Number):void{
			//make sure items are selected up to the target name
			//and any items after are not selected
			var currentItem:RatingItem;
			for (var i:int = 0; i < itemCount; i++)
			{
				if(getChildByName(i.toString()) is RatingItem){
				currentItem = RatingItem(getChildByName(i.toString()));
				if (currentItem)
				{
					if (i <= value)
					{
						//selected		
						currentItem.selected = true;
					}
					else
					{
						//not selected
						currentItem.selected = false;
					}
				}
				}
			}
			
		}
		
		
		private function handleMouseRoll(event:MouseEvent):void{
			selectItems(Number(event.currentTarget.name));
		}
		
		private function handleMouseOut(event:MouseEvent):void{
			if (event.currentTarget is VoteRenderer)
			{
				selectItems(value);
			}
		}
		
			
		/**
		* handle the click and dispatch the event
		**/
		private function handleItemClick(event:MouseEvent):void
		{	
			
			//prevent the default and stop the propogation
			//so that the base class does not select it.
			event.preventDefault();
			event.stopImmediatePropagation();
			
			if (event.currentTarget.id == 1 && value == 1){
				value=0;
			}
			else{
				value= Number(event.currentTarget.id); 
			}
			
			dispatchEvent(event);
			
		}	

	}
}
RatingItem - звездочка.

Старый 06.05.2008, 20:23
Sneg вне форума Посмотреть профиль Отправить личное сообщение для Sneg Найти все сообщения от Sneg
  № 13  
Ответить с цитированием
Sneg
 
Аватар для Sneg

Регистрация: Oct 2005
Адрес: Russia, Moscow
Сообщений: 316
Отправить сообщение для Sneg с помощью ICQ
По правде говоря, ужасный код, в котором разбираться нет времени и желания.

Что хотели получить от этого рендерера? Зачем было реализовывать все интерфейсы самому? Что мешало расширить стандартный рендерер?

Старый 06.05.2008, 20:45
Borman2000 вне форума Посмотреть профиль Отправить личное сообщение для Borman2000 Найти все сообщения от Borman2000
  № 14  
Ответить с цитированием
Borman2000
 
Аватар для Borman2000

Регистрация: Dec 2006
Сообщений: 50
Отправить сообщение для Borman2000 с помощью ICQ
Цитата:
Сообщение от Sneg Посмотреть сообщение
По правде говоря, ужасный код,
Все вопросы к бразильцам - код мне от них достался в наследство.

Цитата:
Сообщение от Sneg Посмотреть сообщение
в котором разбираться нет времени и желания.
Понимаю...

Цитата:
Сообщение от Sneg Посмотреть сообщение
Что хотели получить от этого рендерера? Зачем было реализовывать все интерфейсы самому? Что мешало расширить стандартный рендерер?
Требования функционала. В случае с один типом элементов (RatingItem) все выглядит красиво. Но мне надо добавить еще один тип - РадиоБаттон.

Старый 06.05.2008, 21:06
Sneg вне форума Посмотреть профиль Отправить личное сообщение для Sneg Найти все сообщения от Sneg
  № 15  
Ответить с цитированием
Sneg
 
Аватар для Sneg

Регистрация: Oct 2005
Адрес: Russia, Moscow
Сообщений: 316
Отправить сообщение для Sneg с помощью ICQ
Строчка var newItem = new RadioButton; навереное имеется ввиду new RadioButton() ?

Старый 06.05.2008, 21:19
Borman2000 вне форума Посмотреть профиль Отправить личное сообщение для Borman2000 Найти все сообщения от Borman2000
  № 16  
Ответить с цитированием
Borman2000
 
Аватар для Borman2000

Регистрация: Dec 2006
Сообщений: 50
Отправить сообщение для Borman2000 с помощью ICQ
Цитата:
Сообщение от Sneg Посмотреть сообщение
Строчка var newItem = new RadioButton; навереное имеется ввиду new RadioButton() ?
Тип того

Старый 08.05.2008, 12:34
Borman2000 вне форума Посмотреть профиль Отправить личное сообщение для Borman2000 Найти все сообщения от Borman2000
  № 17  
Ответить с цитированием
Borman2000
 
Аватар для Borman2000

Регистрация: Dec 2006
Сообщений: 50
Отправить сообщение для Borman2000 с помощью ICQ
Разрешил проблему ViewStack'ом и двумя рендерами. Хоть и инициализация первой записи по прежнему происходит дважды, но этого не видно за счет того, что рендерер отображает тока один тип компонента. ))

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

Теги
datagrid , itemrenderer

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

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


 


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


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