VistaFlowContainer.as
上传用户:chuer333
上传日期:2022-06-13
资源大小:906k
文件大小:3k
源码类别:

FlashMX/Flex源码

开发平台:

Flex

  1. package com.dougmccune.containers
  2. {
  3. import caurina.transitions.Tweener;
  4. import flash.display.DisplayObject;
  5. import flash.events.KeyboardEvent;
  6. import flash.geom.ColorTransform;
  7. import flash.ui.Keyboard;
  8. import mx.managers.IFocusManagerComponent;
  9. import org.papervision3d.objects.DisplayObject3D;
  10. public class VistaFlowContainer extends CoverFlowContainer implements IFocusManagerComponent
  11. {
  12. public function VistaFlowContainer()
  13. {
  14. super();
  15. this.rotationAngle = -25;
  16. addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
  17. }
  18. override public function addChild(child:DisplayObject):DisplayObject {
  19. var child:DisplayObject = super.addChild(child);
  20. var plane:DisplayObject3D = lookupPlane(child);
  21. plane.material.doubleSided = true;
  22. var reflection:DisplayObject3D = lookupReflection(child);
  23. if(reflection)
  24. reflection.material.doubleSided = true;
  25. return child;
  26. }
  27. override protected function keyDownHandler(event:KeyboardEvent):void {
  28. if(event.keyCode == Keyboard.LEFT || event.keyCode == Keyboard.UP) {
  29. if(selectedIndex < numChildren - 1) {
  30. selectedIndex++;
  31. }
  32. else {
  33. selectedIndex=0;
  34. }
  35. }
  36. else if(event.keyCode == Keyboard.RIGHT || event.keyCode == Keyboard.DOWN) {
  37. if(selectedIndex > 0) {
  38. selectedIndex--;
  39. }
  40. else {
  41. selectedIndex = numChildren-1;
  42. }
  43. }
  44. }
  45. override protected function layoutChildren(unscaledWidth:Number, unscaledHeight:Number):void {
  46. layoutVistaFlow(unscaledWidth, unscaledHeight);
  47. }
  48. protected function layoutVistaFlow(uncaledWidth:Number, unscaledHeight:Number):void {
  49. var n:int = numChildren;
  50. for(var i:int=0; i<n; i++) {
  51. var child:DisplayObject = getChildAt(i);
  52. child.visible = false;
  53. var plane:DisplayObject3D = lookupPlane(child);
  54. if(plane == null) {
  55. continue;
  56. }
  57. plane.container.visible = true;
  58. var stackIndex:int = (i - selectedIndex);
  59. var horizontalGap:Number = getStyle("horizontalSpacing");
  60. if(isNaN(horizontalGap)) {
  61. //this seems to work fairly well as a default
  62. horizontalGap = maxChildHeight/3;
  63. }
  64. var verticalGap:Number = getStyle("verticalSpacing");
  65. if(isNaN(verticalGap)) {
  66. verticalGap = 10;
  67. }
  68. var xPosition:Number = -stackIndex * horizontalGap;
  69. var yPosition:Number = -(maxChildHeight - child.height)/2;
  70. var zPosition:Number = camera.z/2 + stackIndex * verticalGap + 100;
  71. var yRotation:Number = rotationAngle;
  72. if(i < selectedIndex) {
  73. xPosition += horizontalGap*3;
  74. yPosition -= 150;
  75. zPosition += 100;
  76. }
  77. if(reflectionEnabled) {
  78. var reflection:DisplayObject3D = lookupReflection(child);
  79. if(fadeEdges) {
  80. reflection.material.updateBitmap();
  81. }
  82. //drop the reflection down below the plane and put in a gap of 2 pixels. Why 2 pixels? I think it looks nice.
  83. var reflY:Number = yPosition - child.height - 2;
  84. reflection.visible = i >= selectedIndex;
  85. reflection.rotationY = yRotation;
  86. Tweener.addTween(reflection, {z:zPosition, time:tweenDuration/3});
  87. Tweener.addTween(reflection, {x:xPosition, y:reflY, rotationY:yRotation, time:tweenDuration});
  88. }
  89. plane.rotationY = yRotation;
  90. Tweener.addTween(plane, {z:zPosition, time:tweenDuration/3});
  91. Tweener.addTween(plane, {x:xPosition, y:yPosition, time:tweenDuration});
  92. }
  93. }
  94. }
  95. }