/* * Copyright 2008 (c) Lance Pollard * www.systemsofseven.com/blog * www.4ddesignlab.com * LanceJPollard@gmail.com * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ package com.fourD.actions { import com.fourD.events.LayoutActionEvent; import flash.display.DisplayObject; import flash.events.Event; import mx.core.UIComponent; import com.fourD.core.SimpleZSorter; public class SimpleLayoutAction extends LayoutAction { public function SimpleLayoutAction() { ambientActiveDuringItemSelection = false; } /** INTRO */ override protected function introStart():void { var layoutElement:UIComponent; var i:int=0; var numOfItems:int = target.numLayoutElements; if (!preferredLayoutElementWidth) { preferredLayoutElementWidth = 120; } if (!preferredLayoutElementHeight) { preferredLayoutElementHeight = 120; } layout.initializeLayoutEquation(); for (i; i < numOfItems; i++) { layoutElement = target.getLayoutElementAt(i) as UIComponent; layoutElement.alpha = 0; //layoutElement.setActualSize(20, 20); token = new Object(); token.width = preferredLayoutElementWidth; token.height = preferredLayoutElementHeight; token.x = Math.random() * 10000; token.y = Math.random() * 10000; token.z = Math.random() * 10000; if (i == numOfItems - 1) { token.onComplete = dispatchLayoutActionEvent token.onCompleteParams = [LayoutActionEvent.INTRO_END]; } animator.tween([token], null, layoutElement as DisplayObject); } } // introEnd is only called if you interrupt the intro with a click or something. // by default, clicking does nothing to the intro, but if you want to be crazy, // override this method. override protected function introEnd():void { var layoutElement:UIComponent; var i:int=0; var numOfItems:int = target.numLayoutElements; layout.initializeLayoutEquation(); for (i; i < numOfItems; i++) { layoutElement = target.getLayoutElementAt(i) as UIComponent; token = layout.getLayoutElementToken(layoutElement, i); token.alpha = 1; //layoutElement.setActualSize(token.width, token.height); if (i == numOfItems - 1) { token.onComplete = introComplete; } animator.tween([token], null, layoutElement as DisplayObject); } } override protected function introComplete():void { dispatchLayoutActionEvent(LayoutActionEvent.INTRO_COMPLETE); } /** AMBIENT */ override protected function ambientStart():void { container.addEventListener(Event.ENTER_FRAME, ambientUpdate); } override protected function ambientUpdate(event:Event):void { if (layout.selectedIndexHitTest) { layout.handleSelectedIndexHitTest(); } var rotY:Number = (target.stage.mouseX - (target.stage.stageWidth/2)) * 1/300; container.rotationY += rotY; target.invalidateDisplayList(); } override protected function ambientEnd():void { // on tweenComplete, dispatch ambientComplete ambientComplete(); } override protected function ambientComplete():void { dispatchLayoutActionEvent(LayoutActionEvent.AMBIENT_COMPLETE); container.removeEventListener(Event.ENTER_FRAME, ambientUpdate); } /** ITEM_SELECTED */ override protected function itemSelectedStart():void { token = new Object(); var numOfItems:Number = target.numLayoutElements; var degree:Number = (layout.selectedIndex / numOfItems) * 360; var remainder:Number = (360 - (container.rotationY % 360)); if (container.rotationY < 360) { token.rotationY = degree; } else if (remainder == 0) { token.rotationY = degree; } else if (container.rotationY > 360 && remainder != 0) { token.rotationY = remainder + degree; } token.rotationY += 10; token.z = -300; token.onComplete = dispatchLayoutActionEvent; token.onCompleteParams = [LayoutActionEvent.ITEM_SELECTED_END]; animator.tween([token], null, container); } override protected function itemSelectedEnd():void { var layoutElement:DisplayObject = target.getLayoutElementAt(layout.selectedIndex) as DisplayObject; token = new Object(); token.scaleX = token.scaleY = 1.2; token.onComplete = dispatchLayoutActionEvent; token.onCompleteParams = [LayoutActionEvent.ITEM_SELECTED_COMPLETE]; animator.tween([token], null, layoutElement); } override protected function itemSelectedComplete():void { } /** ITEM_DESELECTED */ override protected function itemDeselectedStart():void { trace("Item deselected start"); var layoutElement:DisplayObject = target.getLayoutElementAt(layout.selectedIndex) as DisplayObject; token = new Object(); token.scaleX = token.scaleY = 1; token.onComplete = dispatchLayoutActionEvent; token.onCompleteParams = [LayoutActionEvent.ITEM_DESELECTED_END]; animator.tween([token], null, layoutElement); } override protected function itemDeselectedEnd():void { token = new Object(); token.z = 0; token.onComplete = itemDeselectedComplete animator.tween([token], null, container); } override protected function itemDeselectedComplete():void { dispatchLayoutActionEvent(LayoutActionEvent.ITEM_DESELECTED_COMPLETE); } /** OUTRO */ override public function outro():void { dispatchLayoutActionEvent(LayoutActionEvent.OUTRO_START); } override protected function outroStart():void { } override protected function outroEnd():void { } override protected function outroComplete():void { } } }