import mx.xpath.XPathAPI; //import util.StringUtility; /* * class that displays a number of images, loaded externally... */ class imageViewers.SimpleViewer { private var target_mc:MovieClip; private var images_xml:XML; private var currentImage:MovieClip; private var nextImage:MovieClip; private var interval:Number; // loader variables private var movLoader:MovieClipLoader; private var movLoadListener:Object; private var whichMovie:Number; private var files:Array; /* * CONSTRUCTOR */ public function SimpleViewer(images:XML, target:MovieClip) { images_xml = images; target_mc = target; movLoader = new MovieClipLoader(); movLoadListener = new Object(); whichMovie = 0; init(); } /* * */ private function init():Void { getFiles(); // start showing the images interval = setInterval(transition, 72); } /* * function to get all external files to load * * @xml: the XML holding the image info */ private function getFiles(xml:XML):Void { var path:String = "/table/row/images/" } /* * function to create a transition between two MCs */ private function transition():Void { // place the next image in front nextImage.swapDepths(currentImage); // nextImage is now the current image currentImage = nextImage; // load the next image } /* * function to place text on a TextField * * @field: the TextField to place the text in. * @txt: the text to place. */ private function placeText(field:TextField, txt:String):Void { // set the text to the TextField field.text = txt; } /* * creates an invisible MC to load movies in outside the main MC * can be used to cache other movies, while the main movie is loaded. */ function buildLoadArea() { trace("buildLoadArea()"); _root.createEmptyMovieClip("invisible_loader_mc", _root.getNextHighestDepth()); invisible_loader_mc._x = width*-1; invisible_loader_mc._y = height*-1; invisible_loader_mc._visible = false; } /* * Removes all instances created to load files. */ function loadDestroy() { trace("destroy()"); invisible_loader_mc.removeMovieClip(); invisible_loader_mc.unloadClip(); loader_mc.removeMovieClip(); loader_mc.unloadClip(); //movLoader.removeMovieClip(); movLoader.unloadClip(); movLoader.removeListener(moveLoadListener); delete movLoadListener; } /* * loads an external movie * * @file: The external movie to load * @target: The MC to load the movie in */ function loadExternalMovie(file:String, target:MovieClip):Void{ trace("Loading: " + file + "..."); trace("whichMovie = " + whichMovie); if (whichMovie == 0) { target_mc.attachMovie("loader", "loader_mc", target_mc.getNextHighestDepth()); loader_mc._x = width / 2; loader_mc._y = height / 2; movLoadListener.onLoadStart = loadStart; movLoadListener.onLoadProgress = loadProgress; } movLoadListener.onLoadError = loadError; movLoadListener.onLoadInit = loadInit; movLoader.addListener(movLoadListener); movLoader.loadClip(file, target); } /* * loads the next movie (if available) */ function loadNextMovie() { trace("loadNextMovie()"); whichMovie++; if (whichMovie >= movies.length) { destroy(); return; } loadExternalMovie(movies[whichMovie], invisible_loader_mc); } /* * invoked when a call to MovieClipLoader.loadClip() has successfully begun to download a file. */ function loadStart(target_mc) { // initiate your progress indicators trace("loadstart()"); loader_mc.loaderText_txt.text = "0 KB loaded"; loader_mc.mask_mc._xscale = 0; } /* * invoked every time the loading content is written to disk during the loading process */ function loadProgress(target_mc, loadedBytes, totalBytes){ trace("loadProgress()"); percentage = (!isNaN(loadedBytes/totalBytes)) ? Math.ceil((loadedBytes * 100)/totalBytes) : 0 ; // make sure your percentage value never goes higher than 100 if(percentage > 100) percentage = 100; //trace("loaded: " + percentage + "%"); // update your progress indicators loader_mc.loaderText_txt.text = Math.ceil(loadedBytes/1024) + "/" + Math.ceil(totalBytes/1024) + "KB loaded"; loader_mc.mask_mc._xscale = percentage; } /* * invoked when a file loaded with MovieClipLoader.loadClip() has failed to load */ function loadError(target_mc, errorCode) { trace("Load error: " + errorCode); loadNextMovie(); } /* * called after the movie is loaded */ function loadInit(target_mc) { trace("Loaded: " + movies[whichMovie]); _root.loader_mc.removeMovieClip(); loadNextMovie(); } }