/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

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