Created
August 11, 2015 15:44
-
-
Save ek/ecfc6f328b5f9c4010bc to your computer and use it in GitHub Desktop.
SlideshowView.as - ActionScript 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package wolken.slideshow { | |
import flash.events.Event; | |
import flash.events.EventDispatcher; | |
import flash.text.TextField; | |
import flash.display.MovieClip; | |
import flash.display.LoaderInfo; | |
import flash.display.SimpleButton; | |
import fl.transitions.Tween; | |
import fl.transitions.TweenEvent; | |
import fl.transitions.easing.*; | |
import flash.utils.Timer; | |
import flash.events.TimerEvent; | |
import caurina.transitions.*; | |
import flash.events.MouseEvent; | |
public class SlideshowView extends MovieClip { | |
private var _loader:SlideshowLoader; | |
private var _config:SlideshowConfig; | |
private var _rootClip:MovieClip; | |
private var _imagesClip:MovieClip; | |
private var _button_0:SimpleButton; | |
private var _button_1:SimpleButton; | |
private var _button_2:SimpleButton; | |
private var _textfield:TextField; | |
private var i:int; | |
public var imageWidth:int = 367; | |
public var borderOffset:int = 16; | |
public var currentIndex:int = 100; | |
public var newIndex:int; | |
private var _orange_1:MovieClip; | |
private var _orange_2:MovieClip; | |
private var _orange_3:MovieClip; | |
private var _grey_1:MovieClip; | |
private var _grey_2:MovieClip; | |
private var _grey_3:MovieClip; | |
private var _oranges:Array; | |
private var _greys:Array; | |
private var _preload_mc:MovieClip; | |
private var _preload_bar:MovieClip; | |
private var _buttonClip:MovieClip; | |
private var _textfield_cover:MovieClip; | |
private var _barTween; | |
public function SlideshowView( config:SlideshowConfig, loader:SlideshowLoader, rootClip:MovieClip ) { | |
_rootClip = rootClip; | |
_config = config; | |
_loader = loader; | |
_imagesClip = _rootClip.images_mc; | |
_buttonClip = _rootClip.buttons_mc; | |
_textfield_cover = _rootClip.textfield_cover_mc; | |
_imagesClip.alpha = 0; | |
_buttonClip.alpha = 0; | |
_imagesClip.visible = false; | |
_buttonClip.visible = false; | |
_preload_mc = _rootClip.preload_mc; | |
_preload_bar = _preload_mc.preload_bar; | |
_textfield = _rootClip.text_txt; | |
_textfield.visible = false; | |
_button_0 = _rootClip.buttons_mc.button_0; | |
_button_1 = _rootClip.buttons_mc.button_1; | |
_button_2 = _rootClip.buttons_mc.button_2; | |
_orange_1 = _rootClip.buttons_mc.orange_1; | |
_orange_2 = _rootClip.buttons_mc.orange_2; | |
_orange_3 = _rootClip.buttons_mc.orange_3; | |
_oranges = [ _orange_1, _orange_2, _orange_3 ]; | |
_grey_1 = _rootClip.buttons_mc.grey_1; | |
_grey_2 = _rootClip.buttons_mc.grey_2; | |
_grey_3 = _rootClip.buttons_mc.grey_3; | |
_greys = [ _grey_1, _grey_2, _grey_3 ]; | |
_loader.addEventListener( Event.COMPLETE, loaderComplete ); | |
_loader.addEventListener( Event.CHANGE, loaderChange ); | |
_config.addEventListener( Event.COMPLETE, configComplete ); | |
_button_0.addEventListener( MouseEvent.ROLL_OVER, rollOverButton ); | |
_button_1.addEventListener( MouseEvent.ROLL_OVER, rollOverButton ); | |
_button_2.addEventListener( MouseEvent.ROLL_OVER, rollOverButton ); | |
} | |
private function configComplete(event:Event) { | |
} | |
private function loaderComplete(event:Event) { | |
for( i=0; i < 3; i++ ) { | |
if( _loader.images[i].sprite != null ) { | |
var imageClip = _imagesClip.addChild(_loader.images[i].sprite); | |
imageClip.x = i * imageWidth; | |
} | |
} | |
changeImage(0); | |
} | |
public function changeImage(index) { | |
newIndex = index; | |
if(currentIndex != newIndex) { | |
var newX = - ( newIndex * imageWidth ) + borderOffset; | |
moveImage(newX); | |
currentIndex = newIndex; | |
changeButton(newIndex); | |
changeText(newIndex); | |
} | |
} | |
private function changeText(newIndex) { | |
_textfield.text = _config.images[newIndex]['text']; | |
} | |
private function changeButton(newIndex) { | |
for(i=0;i<=2;i++) { | |
_oranges[i].visible = false; | |
_greys[i].visible = true; | |
} | |
_oranges[newIndex].visible = true; | |
_greys[newIndex].visible = false; | |
} | |
private function moveImage(newX) { | |
Tweener.addTween( _imagesClip, { x: newX, time: .5, transition:"easeOutCubic", delay: 0 }); | |
} | |
private function rollOverButton(event:Event) { | |
//trace(event.target.name); | |
var buttonName:String = event.target.name; | |
switch (buttonName) { | |
case 'button_0' : | |
changeImage(0); | |
break; | |
case 'button_1' : | |
changeImage(1); | |
break; | |
case 'button_2' : | |
changeImage(2); | |
break; | |
default : | |
trace("unknown button name"); | |
} | |
} | |
private function loaderChange(event:Event) { | |
var percent_loaded = ( _loader.currentIndex + 1 ) / 3 ; | |
if(percent_loaded >= 1) { | |
percent_loaded = 1; | |
viewLoadingComplete(); | |
} | |
Tweener.addTween( _preload_bar, { scaleX: percent_loaded, time: .35, transition:"easeOutCubic", delay: 0 }); | |
} | |
private function viewLoadingComplete() { | |
_imagesClip.visible = true; | |
_buttonClip.visible = true; | |
_textfield.visible = true; | |
Tweener.addTween( _imagesClip, { alpha: 1, time: .5, transition:"easeOutCubic", delay: .35 }); | |
Tweener.addTween( _buttonClip, { alpha: 1, time: .5, transition:"easeOutCubic", delay: .85 }); | |
Tweener.addTween( _textfield_cover, { alpha: 0, time: .5, transition:"easeOutCubic", delay: 1.20 }); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment