PageRenderTime 384ms CodeModel.GetById 161ms app.highlight 4ms RepoModel.GetById 218ms app.codeStats 0ms

/src/away3d/controllers/ControllerBase.as

http://github.com/away3d/away3d-core-fp11
ActionScript | 85 lines | 56 code | 15 blank | 14 comment | 13 complexity | 35ac03cdf83d41f37ee48b132950a965 MD5 | raw file
 1package away3d.controllers
 2{
 3	import away3d.arcane;
 4	import away3d.entities.*;
 5	import away3d.errors.AbstractMethodError;
 6	
 7	use namespace arcane;
 8	
 9	public class ControllerBase
10	{
11		protected var _autoUpdate:Boolean = true;
12		protected var _targetObject:Entity;
13		
14		protected function notifyUpdate():void
15		{
16			if (_targetObject && _targetObject.implicitPartition && _autoUpdate)
17				_targetObject.implicitPartition.markForUpdate(_targetObject);
18		}
19		
20		/**
21		 * Target object on which the controller acts. Defaults to null.
22		 */
23		public function get targetObject():Entity
24		{
25			return _targetObject;
26		}
27		
28		public function set targetObject(val:Entity):void
29		{
30			if (_targetObject == val)
31				return;
32			
33			if (_targetObject && _autoUpdate)
34				_targetObject._controller = null;
35			
36			_targetObject = val;
37			
38			if (_targetObject && _autoUpdate)
39				_targetObject._controller = this;
40			
41			notifyUpdate();
42		}
43		
44		/**
45		 * Determines whether the controller applies updates automatically. Defaults to true
46		 */
47		public function get autoUpdate():Boolean
48		{
49			return _autoUpdate;
50		}
51		
52		public function set autoUpdate(val:Boolean):void
53		{
54			if (_autoUpdate == val)
55				return;
56			
57			_autoUpdate = val;
58			
59			if (_targetObject) {
60				if (_autoUpdate)
61					_targetObject._controller = this;
62				else
63					_targetObject._controller = null;
64			}
65		}
66		
67		/**
68		 * Base controller class for dynamically adjusting the propeties of a 3D object.
69		 *
70		 * @param    targetObject    The 3D object on which to act.
71		 */
72		public function ControllerBase(targetObject:Entity = null):void
73		{
74			this.targetObject = targetObject;
75		}
76		
77		/**
78		 * Manually applies updates to the target 3D object.
79		 */
80		public function update(interpolate:Boolean = true):void
81		{
82			throw new AbstractMethodError();
83		}
84	}
85}