Righty, so I started making a little Slideshow app, it loads the image URL reference from an XML file, sends those to a BulkLoader to preload all the images and starts the slideshow after the preload. Added all the controls I need, which are all working fine.
I’m using this slideshow to show the images of different projects, meaning when I click a specific project btn it changes the XML value of the the Slideshow app. Problem is, the XML value changes BUT the loader obviously doesn’t reload itself and the “new” slideshow doesn’t show. I’ve been thinking of adding an entire new instance of the Slideshow, addChild(new Slideshow());, on click but haven’t figured out how to actually remove the child of a class + this seems rather bulky to me.
Any clues on how to get it done?
Thanks,
Kevin
package be.bundl{
import br.com.stimuli.loading.BulkLoader;
import br.com.stimuli.loading.BulkProgressEvent;
import flash.events.*;
import flash.display.*;
import flash.media.*;
import flash.net.*;
import flash.utils.*;
import gs.*;
import flash.text.TextField;
public class Slideshow extends MovieClip {
public var loader:BulkLoader;
public static var _xml:XMLList;
private var _array:Array;
private var _num:uint;
private var _container:Sprite;
private var _bitmap:Bitmap;
private var _play:Sprite;
private var _pause:Sprite;
private var _next:Sprite;
private var _prev:Sprite;
private var _spec:Sprite;
private var _specTxt:TextField;
private var _myTimer:Timer;
public function Slideshow() {
loader=new BulkLoader("main-site");
for (var i:uint=0; i < _xml.length(); i++) {
loader.add(_xml*.toString());
specBtn(i);
}
loader.addEventListener(BulkLoader.COMPLETE, onAllItemsLoaded);
loader.addEventListener(BulkLoader.PROGRESS, onAllItemsProgress);
loader.start();
}
public function onAllItemsLoaded(evt:Event):void {
trace("every thing is loaded!");
container();
makeLoader();
controls();
}
private function container():void {
_container = new Sprite();
addChild(_container);
}
private function controls():void {
nextBtn();
prevBtn();
pauseBtn();
playBtn();
addListeners();
makeTimer();
}
private function makeLoader():void {
_bitmap=loader.getBitmap(_xml[_num]);
_bitmap.y=0;
_container.addChild(_bitmap);
}
//DRAW BUTTONS
private function playBtn():void {
_play = new Sprite();
_play.graphics.beginFill(0xCC00CC);
_play.graphics.drawRect(300,200,200,20);
_play.graphics.endFill();
addChild(_play);
}
private function pauseBtn():void {
_pause = new Sprite();
_pause.graphics.beginFill(0x0000CC);
_pause.graphics.drawRect(0,200,200,20);
_pause.graphics.endFill();
addChild(_pause);
}
private function nextBtn():void {
_next = new Sprite();
_next.graphics.beginFill(0x000000);
_next.graphics.drawRect(_bitmap.width/2,0,_bitmap.width/2,_bitmap.height);
_next.graphics.endFill();
_next.alpha = 0.1;
addChild(_next);
}
private function prevBtn():void {
_prev = new Sprite();
_prev.graphics.beginFill(0x000000);
_prev.graphics.drawRect(0,0,_bitmap.width/2,_bitmap.height);
_prev.graphics.endFill();
_prev.alpha = 0.1;
addChild(_prev);
}
private function specBtn(j:uint):void {
_spec = new Sprite();
_spec.y = 400;
_spec.x = j*20;
addChild(_spec);
_specTxt = new TextField();
_specTxt.text = (j + 1).toString();
_spec.addChild(_specTxt);
_spec.addEventListener(MouseEvent.CLICK, test);
function test(evt:MouseEvent):void {
_num = j;
tweenImg();
_myTimer.stop();
_play.visible = true;
_pause.visible = false;
}
}
//LISTENERS AND FUNCTIONS
private function addListeners():void {
_next.addEventListener(MouseEvent.CLICK, nextImg);
_prev.addEventListener(MouseEvent.CLICK, prevImg);
_play.addEventListener(MouseEvent.CLICK, playImg);
_pause.addEventListener(MouseEvent.CLICK, pauseImg);
}
private function playImg(evt:MouseEvent):void {
_myTimer.start();
_play.visible = false;
_pause.visible = true;
}
private function pauseImg(evt:MouseEvent):void {
_myTimer.stop();
_play.visible = true;
_pause.visible = false;
}
private function nextImg(evt:MouseEvent):void {
if (_num<(_xml.length - 1)) {
_num++;
tweenImg();
_myTimer.stop();
trace("Timer stopped @ " + getTimer() + " ms");
} else {
_num=0;
tweenImg();
_myTimer.stop();
}
if (_play.visible==false) {
_play.visible=true;
_pause.visible=false;
}
}
private function prevImg(evt:MouseEvent):void {
if (_num>0) {
_num--;
tweenImg();
_myTimer.stop();
trace("Timer stopped @ " + getTimer() + " ms");
} else {
_num=2;
tweenImg();
_myTimer.stop();
}
if (_play.visible==false) {
_play.visible=true;
_pause.visible=false;
}
}
private function tweenImg():void {
TweenFilterLite.to(_container, .5, {blurFilter:{blurX:50, blurY:50}});
TweenFilterLite.to(_container, .5, {alpha:0, delay:.25, onComplete:motionFinishHandler, overwrite:0});
}
private function motionFinishHandler():void {
_container.removeChild(_bitmap);
makeLoader();
TweenFilterLite.to(_container, .5, {alpha:1});
TweenFilterLite.to(_container, .5, {blurFilter:{blurX:0, blurY:0}, delay:.25, overwrite:0 });
}
//TIMER
private function makeTimer():void {
_myTimer=new Timer(3500);//millisecond
_myTimer.addEventListener(TimerEvent.TIMER, runOnce);
_myTimer.start();
_play.visible=false;
}
private function runOnce(event:TimerEvent):void {
trace("runOnce() called @ " + getTimer() + " ms");
if (_num<(_xml.length - 1)) {
_num++;
tweenImg();
} else {
_num=0;
tweenImg();
}
}
public function onAllItemsProgress(evt:BulkProgressEvent):void {
trace(evt.loadingStatus());
}
}
}