Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed dependencies on 'listMask' and 'spinner'

  • Loading branch information...
commit 302f7a4cf9affb9fcbedf0c3b41df038eb0397b2 1 parent 15acd97
@scottalan scottalan authored
View
610 com/tmtdigital/dash/display/Playlist.as
@@ -1,609 +1 @@
-/**
- * Playlist.as - See class description for information.
- *
- * Author - Travis Tidwell ( travist@tmtdigital.com )
- * License - General Public License ( GPL version 3 )
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see http://www.gnu.org/licenses/
- **/
-package com.tmtdigital.dash.display
-{
- import com.tmtdigital.dash.display.Skinable;
- import com.tmtdigital.dash.display.node.Teaser;
- import com.tmtdigital.dash.display.node.NodeBase;
- import com.tmtdigital.dash.display.PlaylistLinks;
- import com.tmtdigital.dash.display.Navigation;
- import com.tmtdigital.dash.events.DashEvent;
- import com.tmtdigital.dash.utils.Utils;
- import com.tmtdigital.dash.utils.LayoutManager;
- import com.tmtdigital.dash.utils.Pager;
- import com.tmtdigital.dash.net.Gateway;
- import com.tmtdigital.dash.net.Service;
- import com.tmtdigital.dash.display.media.MediaPlayer;
- import com.tmtdigital.dash.display.controls.ScrollRegion;
- import com.tmtdigital.dash.config.Params;
-
- import flash.events.*;
- import flash.display.*;
- import flash.geom.*;
- import flash.text.*;
- import flash.utils.*;
-
- /**
- * The Playlist class is the display object to show the Playlist of the media player
- */
- public class Playlist extends Skinable
- {
- /**
- * Constructor for the Playlist.
- *
- * @param skin - The skin to be used for this playlist.
- */
- public function Playlist( _skin:MovieClip )
- {
- super( _skin );
- }
-
- /**
- * Called from the Skinable class to set the skin for all of the elements within this MovieClip.
- *
- * @param skin - The skin MovieClip for the playlist.
- */
- public override function setSkin( _skin:MovieClip )
- {
- // Set the Skinable class first.
- super.setSkin(_skin);
-
- navigation = new Navigation( skin.navigation );
- links = new PlaylistLinks( skin.links );
- scrollRegion = new ScrollRegion( skin.scrollRegion );
-
- service = Service.GET_VIEW;
- selectedPage = 0;
- selectedIndex = 0;
-
- // Set up the pager.
- loaded = false;
- pager = new Pager( Params.flashVars.shuffle );
- pager.addEventListener( DashEvent.LOAD_PAGE, onPageLoad );
- pager.addEventListener( DashEvent.LOAD_INDEX, onIndexLoad );
-
- spinner = new Spinner( skin.loader, "playlist" );
- }
-
- // Called when the pager tells us to load a given page.
- private function onPageLoad( event:DashEvent )
- {
- getPlaylist( playlistName );
- }
-
- // Called when the pager tells us to load a particular index.
- private function onIndexLoad( event:DashEvent )
- {
- loadIndex( pager.currentIndex );
- }
-
- /**
- * Sets a vote within this playlist.
- *
- * @param nodeId - The node ID of the item in the playlist you would like to set.
- * @param vote - The vote object that you are using to set the vote to.
- */
- public function setVote( nodeId:Number, vote:Object )
- {
- if (nodeId) {
- var teaser:Teaser = getTeaser( nodeId );
- if( teaser ) {
- teaser.fields.voter.setVote( vote );
- }
- }
- }
-
- /**
- * Loads a playlist given the playlist name.
- *
- * @param - The name of the playlist to load.
- */
- public function loadPlaylist( _playlistName:String = null )
- {
- // If they did not provide a playlist name, then we will try the FlashVars.
- if (! _playlistName) {
- _playlistName = Params.flashVars.playlist;
- }
-
- if ( _playlistName && skin ) {
- pager.pageLimit = Params.flashVars.pagelimit;
- pager.pageIndex = Params.flashVars.playlistpage;
- pager.currentIndex = Params.flashVars.playlistindex;
- if( pager.currentIndex > 0 ) {
- pager.loadState = "current";
- }
-
- playlistName = _playlistName;
-
- // Setup the links.
- links.loadLinks();
-
- // Reset our arguments array.
- resetArguments();
-
- // If there is a navigation bar, then we will want to load that here.
- if (navigation.skin) {
- navigation.loadNavigation();
- }
-
- // Get the playlist.
- getPlaylist( playlistName );
- }
- }
-
- /**
- * Gets the node at a given index.
- *
- * @param - The index in the playlist to get.
- *
- * @return - The teaser at that index.
- */
- public function getNode( index:uint ):Teaser
- {
- // Make sure the index is within our array size.
- if (index < scrollRegion.elements.length) {
- // Return the teaser at this index.
- return (scrollRegion.getItem(index) as Teaser);
- } else {
- // Otherwise return NULL.
- return null;
- }
- }
-
- // Gets a teaser given any node Id for any element within the playlist.
- private function getTeaser( nodeId:Number ) : Teaser
- {
- if( scrollRegion )
- {
- var i:Number = scrollRegion.elements.length;
- while( i-- ) {
- var teaser:Teaser = (scrollRegion.getItem(i) as Teaser);
- if( teaser.node && (teaser.node.nid == nodeId) ) {
- return teaser;
- }
- }
- }
- return null;
- }
-
- /**
- * Returns the media object for the selected teaser.
- *
- * @return MediaPlayer - The media player object.
- */
- public function get media():MediaPlayer
- {
- return Params.flashVars.teaserplay ? teaserMedia : null;
- }
-
- /**
- * Loads any node within our playlist given the node Id.
- *
- * @param - The node object or Id of the node you would like to load.
- */
- public function loadNode( _node:* )
- {
- var node:Object = NodeBase.translateNode( _node );
- if ( node && node.nid ) {
- var teaser:Teaser = getTeaser( node.nid );
- if( teaser ) {
- teaser.onNodeLoad( teaser.node );
- }
- else {
- addNode( node );
- }
- }
- }
-
- /**
- * Loads the node for a given index.
- *
- * @param - The index you would like to load.
- */
- protected function loadIndex( index:uint )
- {
- // Get the teaser from this index.
- var teaser:Teaser = getNode(index);
- if (teaser) {
- // Select this teaser.
- selectTeaser( teaser );
-
- // Load the node.
- Gateway.loadNode( teaser.node, Params.flashVars.playlistonly );
- }
- }
-
- // Deselects all of the teasers.
- private function deSelectTeasers()
- {
- // Iterate through all the teasers and deselect them.
- var i:Number = scrollRegion.elements.length;
- while (i--)
- {
- var element:Teaser = (scrollRegion.getItem(i) as Teaser);
- element.setSelect( false );
- }
- }
-
- /**
- * Selects any given teaser, while deselects all other teasers.
- *
- * @param - The teaser you would like to select.
- */
- private function selectTeaser( teaser:Teaser )
- {
- // Deselect all teasers.
- deSelectTeasers();
-
- // Set this item to be visible in the scroll region.
- scrollRegion.setVisible( teaser.index );
-
- // Select this teaser.
- teaser.setSelect( true );
-
- // Set the current pager index.
- pager.currentIndex = teaser.index;
-
- // Save the selected page and index.
- selectedPage = pager.pageIndex;
- selectedIndex = pager.currentIndex;
-
- // Store the media field for this selected teaser.
- if (teaser.fields) {
- teaserMedia = teaser.fields.media;
- }
- }
-
- // Selects the active teaser.
- private function selectActiveTeaser()
- {
- if( pager.pageIndex == selectedPage ) {
- var teaser:Teaser = (scrollRegion.getItem(selectedIndex) as Teaser);
- if( teaser ) {
- teaser.setSelect( true );
- }
- }
- }
-
- /**
- * Get's called after our service returns with a playlist object for us to parse.
- *
- * @param playlist - The playlist object returned from our service call.
- */
- public function onPlaylistLoaded( _playlist:Object )
- {
- // Store our new playlist.
- playlist = _playlist;
-
- if (playlist) {
- // Set the number of pages.
- pager.setNumPages( playlist.total_rows );
-
- if (rootSkin.setNavBar is Function) {
- rootSkin.setNavBar( pager.hasNextPage, pager.hasPrevPage );
- }
-
- // Backwards compatibility
- playlist = playlist.hasOwnProperty("nodes") ? playlist.nodes : playlist;
-
- // Initialize and empty our Scroll Region.
- scrollRegion.initialize( Params.flashVars.autoscroll, Params.flashVars.vertical, Params.flashVars.teaserspace );
- scrollRegion.empty();
-
- //var startTime:uint=getTimer();
-
- // Add all of our teasers.
- addTeasers();
-
- //trace( getTimer()-startTime );
-
- // Setup the scroll region.
- scrollRegion.setupScrollRegion();
-
- // Hide our loader since we are done loading our playlist.
- spinner.visible = false;
-
- // Let our skin hook in here to do something.
- if (rootSkin.onPlaylistLoad is Function) {
- rootSkin.onPlaylistLoad( _playlist );
- }
- }
- }
-
- /**
- * Adds a single node to the playlist
- *
- * @param playlist - The node object to be added to our playlist
- */
- public function addNode( node:Object ) {
- if ( rootSkin.getTeaser is Function ) {
- // Get the teaser skin from our skin.
- var teaserSkin:MovieClip = rootSkin.getTeaser();
- if (teaserSkin) {
- // Create a new teaser object.
- var teaser:Teaser = new Teaser( teaserSkin, scrollRegion.elements.length );
-
- // Theme the teaser.
- LayoutManager.themeTeaser( teaser.skin );
-
- // Add an event listener to trigger when the user clicks on the teaser.
- teaser.addEventListener( DashEvent.NODE_LOADED, eventHandler );
- teaser.addEventListener( DashEvent.TEASER_CLICK, eventHandler );
-
- // set the node object in the teaser.
- teaser.setNode( node );
-
- // Add the item to our scroll region.
- deSelectTeasers();
- selectActiveTeaser();
- pager.setNumItems( 1 );
-
- // Set up the scroll region.
- scrollRegion.initialize( Params.flashVars.autoscroll, Params.flashVars.vertical, Params.flashVars.teaserspace );
- scrollRegion.empty();
- scrollRegion.addItem( teaser, pager.pageLimit );
- scrollRegion.setupScrollRegion();
- }
- }
- }
-
- // Adds all of our teaser nodes to the scroll region.
- private function addTeasers()
- {
- // We only want to continue here if our skin has provided a routine for
- // us to get a new teaser MovieClip.
- if (rootSkin.getTeaser is Function) {
- var teaser:Teaser = null;
-
- // Iterate through all of our nodes in the playlist.
- for each ( var node:Object in playlist ) {
-
- // Get the teaser skin from our skin.
- var teaserSkin:MovieClip = rootSkin.getTeaser();
- if (teaserSkin) {
- // Create a new teaser object.
- teaser = new Teaser( teaserSkin, scrollRegion.elements.length );
-
- // Set the page this teaser is on...
- teaser.page = pager.pageIndex;
-
- // Theme the teaser.
- LayoutManager.themeTeaser( teaser.skin );
-
- // Add an event listener to trigger when the user clicks on the teaser.
- teaser.addEventListener( DashEvent.TEASER_CLICK, eventHandler );
-
- // set the node object in the teaser.
- teaser.node = NodeBase.translateNode( node );
-
- // Add the item to our scroll region.
- scrollRegion.addItem( teaser, pager.pageLimit );
- }
- }
-
- if( teaser ) {
- deSelectTeasers();
- selectActiveTeaser();
-
- if( !Params.flashVars.node ) {
- // Add the node loaded handler to the last teaser.
- teaser.addEventListener( DashEvent.NODE_LOADED, eventHandler );
- }
-
- // Now iterate back through our teasers and load the data.
- var numItems:Number = scrollRegion.elements.length;
- pager.setNumItems( numItems );
- for( var i:Number = 0; i < numItems; i++ ) {
- teaser = (scrollRegion.getItem(i) as Teaser);
- if( teaser ) {
- teaser.setNode( teaser.node );
- }
- }
- }
-
- // If they also provide a node, then we will want to load it last.
- if( Params.flashVars.node ) {
- // Load the node.
- Gateway.loadNode( Params.flashVars.node, Params.flashVars.playlistonly );
- }
- }
- }
-
- /**
- * Sets the filter for the playlist.
- *
- * @param - The argument filter to provide to our playlist.
- * @param - The argument index for our playlist.
- */
- public function setFilter( arg:String, index:int = 0 )
- {
- // Reset the pager index.
- pager.pageIndex = 0;
- links.selectLink( arg );
- resetArguments();
-
- if( arg != "all" ) {
- stuffArguments(index);
- playlistArgs[index] = arg;
- }
-
- // Get the new playlist with these arguments.
- getPlaylist( playlistName );
- }
-
- /**
- * Sets the playlist.
- *
- * @param - The message object used for the service.
- */
- public function setPlaylist( message:Object )
- {
- // Reset the current index.
- pager.currentIndex = 0;
-
- // If they provide a custom service.
- if( message.hasOwnProperty("service") ) {
- service = message.service;
- }
-
- // If they provide a custom playlist name.
- if( message.hasOwnProperty("playlistName") ) {
- playlistName = message.playlistName;
- }
-
- // If they provide the page limit.
- if( message.hasOwnProperty("pageLimit") ) {
- pager.pageLimit = message.pageLimit;
- }
-
- // If they provide the page index.
- if( message.hasOwnProperty("pageIndex") ) {
- pager.pageIndex = message.pageIndex;
- }
-
- // If they provide the arguments to use.
- if( message.hasOwnProperty("args") ) {
- playlistArgs = new Array();
- for each( var arg:String in message.args ) {
- playlistArgs.push(arg);
- }
- }
-
- // Get the playlist.
- getPlaylist( playlistName );
- }
-
- /**
- * Resets the arguments to the defaults.
- */
- private function resetArguments()
- {
- playlistArgs = new Array();
- var args:Object = Params.flashVars.arg;
- for each (var arg:String in args) {
- playlistArgs.push(arg);
- }
- }
-
- /**
- * Stuffs the playlist args array depending on what index they need to put into the args array.
- */
- private function stuffArguments( index:int )
- {
- if (index >= playlistArgs.length) {
- for( var i:Number = playlistArgs.length; i <= index; i++ ) ;
- {
- playlistArgs.push("*");
- }
- }
- }
-
- /**
- * Event handler for handling the teaser and link clicks.
- *
- * @param - The DashEvent that was dispatched.
- */
- private function eventHandler( e:DashEvent )
- {
- switch ( e.type ) {
- case DashEvent.TEASER_CLICK :
- loadIndex( e.target.index );
- break;
-
- case DashEvent.NODE_LOADED :
- e.target.removeEventListener( DashEvent.NODE_LOADED, eventHandler );
- if( !playlist ) {
- spinner.visible = false;
- pager.loadIndex();
- }
- else if( loaded || !Gateway.isNodeLoaded( Params.flashVars.playlistonly ) ) {
- pager.loadIndex();
- }
- loaded = true;
- break;
- }
- }
-
- /**
- * Makes a service call to get the playlist provided all necessary arguments.
- *
- * @param - The name of the playlist you would like to get.
- */
- private function getPlaylist( _playlistName:String )
- {
- if (_playlistName) {
- spinner.visible = true;
- Service.call( service, onPlaylistLoaded, null, _playlistName, pager.pageLimit, pager.pageIndex, playlistArgs );
- }
- }
-
- /**
- * Called after the player is resized.
- */
- public function postResize()
- {
- spinner.postResize( scrollRegion.listMask.width, scrollRegion.listMask.height );
-
- if (scrollRegion) {
- scrollRegion.postResize();
- }
- }
-
- /**
- * The navigation display item.
- */
- public var navigation:Navigation;
-
- /**
- * The playlist links display item.
- */
- public var links:PlaylistLinks;
-
- /**
- * The scroll region display item.
- */
- public var scrollRegion:ScrollRegion;
-
- /**
- * The spinner display item.
- */
- public var spinner:Spinner;
-
- /**
- * The playlist object, which is a list of all of our nodes.
- */
- public var playlist:Object;
-
- /**
- * The pager object, which is used to keep track of the pagination of the playlist.
- */
- public var pager:Pager;
-
- // Private variables.
- private var service:String;
- private var playlistName:String;
- private var playlistArgs:Array;
- private var loaded:Boolean;
- private var selectedPage:Number;
- private var selectedIndex:Number;
- private var teaserMedia:MediaPlayer;
- }
-}
-
+/**
View
487 com/tmtdigital/dash/display/controls/ScrollRegion.as
@@ -1,486 +1 @@
-/**
- * Copyright 2008 - TMTDigital LLC
- *
- * Author: Travis Tidwell (www.travistidwell.com)
- * Version: 1.0
- * Date: June 9th, 2008
- *
- * Description: The ScrollRegion class is used to manage the scrolling
- * capabilities of the Playlist area of the player.
- *
- **/
-
-package com.tmtdigital.dash.display.controls
-{
- import com.tmtdigital.dash.utils.Utils;
- import com.tmtdigital.dash.display.Skinable;
- import com.tmtdigital.dash.display.node.Teaser;
- import com.tmtdigital.dash.events.DashEvent;
- import com.tmtdigital.dash.display.controls.ScrollBar;
- import com.tmtdigital.dash.utils.Resizer;
- import com.tmtdigital.dash.config.Params;
-
- import flash.display.*;
- import flash.events.*;
- import flash.geom.*;
- import flash.utils.*;
- import fl.transitions.*;
- import fl.transitions.easing.*;
-
- public class ScrollRegion extends Skinable
- {
- public function ScrollRegion( _skin:MovieClip )
- {
- super( _skin );
- }
-
- /**
- * Sets the skin of this object.
- *
- * @param - The skin object to set.
- */
- public override function setSkin( _skin:MovieClip )
- {
- super.setSkin( _skin );
-
- list = skin.list;
- scrollBar = new ScrollBar( skin.scrollBar, setListPos );
- scrollBar.addEventListener( DashEvent.PREV, onPrevNext );
- scrollBar.addEventListener( DashEvent.NEXT, onPrevNext );
- scrollBar.addEventListener( DashEvent.STOP, onDragStop );
- listMask = skin.listMask;
- listBack = skin.listBack;
- Utils.removeAllChildren( skin.list );
-
- numColumns = 0;
- autoScrollSpeed = Params.flashVars.scrollspeed;
- magnify = Params.flashVars.magnify;
- magnifysize = (Math.PI / Params.flashVars.diameter);
- amplitude = (Params.flashVars.amplitude / 100);
- currentAmplitude = 0;
- amplitudeIncrement = amplitude / 4;
-
- if( magnify ) {
- maxMagnify = Math.acos(0) / magnifysize;
- }
-
- elements = new Array();
- }
-
- public function postResize()
- {
- if( initialized ) {
- setupScrollRegion();
- }
- }
-
- public function initialize( _autoScroll:Boolean, _vertical:Boolean, _space:int = 0 )
- {
- autoScroll = _autoScroll;
- vertical = _vertical;
- space = _space;
-
- lastRect = new Rectangle(0,0,0,0);
- numRows = 0;
- numColumns = 0;
-
- _x = (_vertical) ? "x" : "y";
- _y = (_vertical) ? "y" : "x";
- _mouseX = (_vertical) ? "mouseX" : "mouseY";
- _mouseY = (_vertical) ? "mouseY" : "mouseX";
- _localY = (_vertical) ? "localY" : "localX";
- _width = (_vertical) ? "width" : "height";
- _height = (_vertical) ? "height" : "width";
-
- listTween = new Tween( list, _y, Strong.easeOut, list[_y], list[_y], Resizer.tweenTime );
- listTween.addEventListener( TweenEvent.MOTION_FINISH, onDragStop );
- listTween.stop();
- }
-
- public function setupScrollRegion()
- {
- list.x = 0;
- list.y = 0;
-
- if( elements.length > 0 ) {
- rowLength = elements[0][_height];
- elementMid = new Point( (elements[0].width / 2), (elements[0].height / 2) );
- }
-
- var _listSize:Number = list[_height];
- if( magnify ) {
- _listSize += 2*amplitude*rowLength;
- }
- listMaskSize = listMask[_width];
- var _listMaskHeight:Number = listMask[_height];
-
- shouldScroll = (_listSize > _listMaskHeight) ? true : false;
- scrollMid = (_listMaskHeight / 2);
-
- scrollBar.setupScrollBar( _listSize, _listMaskHeight );
- listLength = _listSize - _listMaskHeight;
- listRect = new Rectangle();
- listRect[_height] = listLength;
-
- listMaskRect = skin.listMask.getRect( skin.stage );
-
- skin.removeEventListener( MouseEvent.MOUSE_OVER, onScrollOver );
- skin.addEventListener( MouseEvent.MOUSE_OVER, onScrollOver );
-
- initialized = true;
- }
-
- public function onResize()
- {
- if( initialized ) {
- setupScrollRegion();
- }
- }
-
- /**
- * Returns an element in the scroll region list.
- */
- public function getItem( index:int )
- {
- return elements[index];
- }
-
- /**
- * Empty the scroll region list.
- */
- public function empty()
- {
- Utils.removeAllChildren( list );
- elements = new Array();
- }
-
- /**
- * Automatically positions the list to always show the given index.
- *
- * @param - The index you would like to set visible.
- */
- public function setVisible( index:Number )
- {
- // Cache the current list position.
- var listPos:Number = list[_y];
-
- // Make sure our index is within bounds.
- if( index < list.numChildren ) {
- // If the list item at that index is above the visible region, then move the list position to show it.
- if( -elements[index][_y] > list[_y] ) {
- listPos = -elements[index][_y];
- } else if( (elements[index][_y] + elements[index][_height]) > (-list[_y] + listMask[_height]) ) {
- listPos = -((elements[index][_y] + elements[index][_height]) - listMask[_height]);
- }
-
- // If there is a difference in position.
- if( listPos != list[_y] ) {
- // Set the list and handle positions.
- setListPos( listPos, true );
- scrollBar.setListPos( listPos, true );
- }
- }
- }
-
- /**
- * Adds an element to the list region.
- *
- * @param - The skinable element you would like to add.
- * @param - The limit for each page.
- */
- public function addItem( element:Skinable, pageLimit:int = 10 )
- {
- if( element ) {
- setNumElements( element, pageLimit );
- setElementPosition( element );
- list.addChild( element.skin );
- elements.push( element );
- }
- }
-
- /**
- * Sets the number of elements in our list.
- *
- * @param - The skinable element you would like to add.
- * @param - The limit for each page.
- */
- private function setNumElements( element:Skinable, pageLimit:int )
- {
- if( !numRows ) {
- numColumns = Math.floor(listMask[_width] / element[_width]);
- numRows = numColumns ? (pageLimit / numColumns) : pageLimit;
- }
- }
-
- /**
- * Sets the element position within our list.
- *
- * @param - The skinable element you would like to add.
- */
- private function setElementPosition( element:Skinable )
- {
- var spaceY:Number = vertical ? 0 : space;
- var spaceX:Number = vertical ? space : 0;
-
- // Determine if we should wrap...
- if( (list.numChildren % numRows) == 0 ) {
- element[_x] = lastRect[_x] = lastRect[_x] + lastRect[_width] + spaceX;
- element[_y] = lastRect[_y] = spaceY;
- } else {
- element[_y] = lastRect[_y] = lastRect[_y] + lastRect[_height] + spaceY;
- element[_x] = lastRect[_x];
- }
-
- lastRect.width = element.width;
- lastRect.height = element.height;
- }
-
- /**
- * Timer event to see if we are within our list, and automatically scroll if we are.
- *
- * @param - The timer event.
- */
- private function onScrollEvent( e:Event ) : void
- {
- if( listMaskRect.contains( skin.stage.mouseX, skin.stage.mouseY ) ) {
- var mousePos:Number = skin.stage[_mouseY] - listMaskRect[_y];
-
- if( magnify ) {
- // This will create an easing affect to the highest amplitude.
- currentAmplitude += amplitudeIncrement;
- currentAmplitude = (currentAmplitude > amplitude) ? amplitude : currentAmplitude;
- setMagnify( skin.listMask[_mouseX], mousePos, currentAmplitude );
- }
-
- if( autoScroll && shouldScroll ) {
- var delta:int = 0;
- var hyst:uint = 15;
- var scrollMax:uint = autoScrollSpeed;
-
- if( Math.abs(mousePos - scrollMid) > hyst ) {
- // Find the delta.
- delta = scrollMax * ((mousePos - scrollMid) / scrollMid);
-
- // Set the handle position.
- scrollBar.setHandlePos((scrollBar.handlePos + delta), false );
-
- // Set the list position.
- setListPos(scrollBar.getListPos(), false );
- }
- }
- } else {
- if( magnify && (currentAmplitude > 0) ) {
- // This will create an easing affect to zero amplitude.
- currentAmplitude -= amplitudeIncrement;
- currentAmplitude = (currentAmplitude < 0) ? 0 : currentAmplitude;
- setMagnify( skin.listMask[_mouseX], skin.listMask[_mouseY], currentAmplitude );
- } else {
- onScrollOut(null);
- }
- }
- }
-
- /**
- * This function will iterate through all the elements and perform a magnify function
- * to give the illusion that the playlist is being seen through a magnifying glass. This
- * is somewhat processor intensive.
- *
- * @param - The x mouse position.
- * @param - The y mouse position.
- * @param - The amplitude you would like to set this magnify too.
- */
- private function setMagnify( _mouseX:Number, _mouseY:Number, _amplitude:Number )
- {
- currentAmplitude = _amplitude;
-
- // Only continue if they have magnify set to true.
- var listX:Number = -list[_x] + _mouseX;
- var listY:Number = -list[_y] + _mouseY;
-
- // Initialize our variables.
- var dx:Number;
- var dy:Number;
- var cosX:Number;
- var cosY:Number;
- var cos:Number;
- var scale:Number;
-
- // Iterate through all our elements.
- for( var i:Number=0; i < elements.length; i++) {
- // Calculate the mouse y offset from the elements mid point.
- dy = listY - (elements[i][_y] + elementMid[_y]);
-
- // Calculate the amplitude of this element given that offset.
- cosY = (Math.abs(dy) < maxMagnify) ? Math.cos(dy*magnifysize) : 0;
-
- // Make sure that the amplitude is always greater than zero.
- cosY = cos = (cosY >= 0) ? cosY : 0;
-
- // If there are more than one column, then we can do the same for the x direction.
- if( numColumns > 1 ) {
- dx = listX - (elements[i][_x] + elementMid[_x]);
- cosX = (Math.abs(dx) < maxMagnify) ? Math.cos(dx*magnifysize) : 0;
- cosX = (cosX >= 0) ? cosX : 0;
- cos = (cosX < cosY) ? cosX : cosY;
- }
-
- // Calculate the scale...
- scale = 1 + (_amplitude*cos);
-
- // Calculate the scale of this element
- elements[i].scaleX = elements[i].scaleY = scale;
-
- // If there is a next item, then we need to change it's y position...
- if( ((i+1) < elements.length) && (((i%numRows)+1) < numRows) ) {
- elements[i+1][_y] = elements[i][_y] + elements[i][_height];
- }
-
- // If there is an element next to this one, then we need to change it's x position.
- if( (numColumns > 1) && ((i+numRows) < elements.length) ) {
- elements[i+numRows][_x] = elements[i][_x] + elements[i][_width];
- }
- }
- }
-
- private function onScrollOver( e:MouseEvent )
- {
- if( !isOver ) {
- isOver = true;
- skin.addEventListener( Event.ENTER_FRAME, onScrollEvent );
-
- if( !magnify ) {
- skin.addEventListener( MouseEvent.MOUSE_OUT, onScrollOut );
- }
- }
- }
-
- private function onScrollOut( e:MouseEvent )
- {
- if( isOver ) {
- isOver = false;
- skin.removeEventListener( Event.ENTER_FRAME, onScrollEvent );
-
- if( !magnify ) {
- skin.removeEventListener( MouseEvent.MOUSE_OUT, onScrollOut );
- }
- }
- }
-
- private function onPrevNext( e:DashEvent )
- {
- var listPosition:Number = list[_y];
- listPosition += (e.type == DashEvent.PREV) ? rowLength : -rowLength;
- setListPos( listPosition, true );
- scrollBar.setListPos( listPosition, true );
- }
-
- /**
- * Sets the list position.
- *
- * @param - The list poisiton in pixels.
- * @param - Boolean to indicate if we should tween this movement.
- */
- private function setListPos( listPos:Number, tween:Boolean = false )
- {
- listPos = (listPos > 0) ? 0 : listPos;
- listPos = (listPos < -(list[_height] - rowLength)) ? -(list[_height] - rowLength) : listPos;
-
- if( tween ) {
- listTween.stop();
- listTween.begin = list[_y];
- listTween.finish = listPos;
- listTween.start();
- } else {
- list[_y] = listPos;
- }
- }
-
- private function onDragStop(e:Object)
- {
- if( Params.flashVars.teaserplay && elements.length && (elements[0] is Teaser) ) {
- var element:Teaser = getMostVisibleElement();
- setVisible( element.index );
- }
- }
-
- /**
- * Determine which element in the elements list is the most visible and return that element.
- */
- private function getMostVisibleElement() : Teaser
- {
- // Initialize our variable.
- var mostVisible:Teaser = null;
- var listY:Number = Math.abs(list[_y]);
- var previousArea:Number = 0;
-
- // Iterate through all of our elements.
- for each( var element:Teaser in elements ) {
- // Reset the areashown.
- var areaShown:Number = 0;
-
- // If the element is behind the viewable region.
- if( (element[_y] < listY) && ((element[_y] + element[_height]) > listY) ) {
- areaShown = (element[_y] + element[_height]) - listY;
- } else if( (listY <= element[_y]) && ((listY + listMask[_height]) > element[_y]) ) {
- areaShown = (listY + listMask[_height]) - element[_y];
- }
-
- // If this area is larger than the previous, then this is the most visible.
- if( areaShown > previousArea ) {
- mostVisible = element;
- previousArea = areaShown;
- }
- }
-
- // Return the most visible item.
- return mostVisible;
- }
-
- // *** FlashVars *** //
- public var autoScroll:Boolean = true;
- public var vertical:Boolean = true;
-
- public var list:Sprite;
- public var scrollBar:ScrollBar;
- public var listMask:Sprite;
- public var listBack:Sprite;
- public var elements:Array;
-
- private var _x:String;
- private var _y:String;
- private var _mouseX:String;
- private var _mouseY:String;
- private var _localY:String;
- private var _width:String;
- private var _height:String;
-
- private var space:int = 0;
- private var initialized:Boolean = false;
- private var numRows:int = 0;
- private var lastRect:Rectangle;
- private var shouldScroll:Boolean;
- private var scrollMid:Number;
-
- private var listLength:Number;
- private var listRect:Rectangle;
- private var listMaskRect:Rectangle;
-
- private var rowLength:Number;
- private var numColumns:Number;
-
- private var autoScrollSpeed:Number;
-
- private var magnify:Boolean;
- private var amplitude:Number;
- private var magnifysize:Number;
- private var maxMagnify:Number;
- private var currentAmplitude:Number;
- private var amplitudeIncrement:Number;
- private var elementMid:Point;
-
- private var listTween:Tween;
-
- private var listMaskSize:Number;
- private var isOver:Boolean = false;
- }
-}
+/**
Please sign in to comment.
Something went wrong with that request. Please try again.