/********************************************************************************** class XMLSlideshow Document class for the CS4 XML slideshow Flashscript.biz ***********************************************************************************/ package flashscript.CS4slideshow { import flash.display.*; import flash.text.*; import flash.events.*; import flash.utils.Timer; import biz.Flashscript.filters.Bevel; import biz.Flashscript.utils.TextLoader; import biz.Flashscript.utils.LoaderClass; import biz.Flashscript.utils.LoaderClassStatic; import flashscript.CS4slideshow.*; /* We set the size, color and framerate for the movie. This is only required when the movie is compiled using the Flex-SDK but not for CS4. */ [SWF(width="550",height="450",backgroundColor="0xF1F5F9",frameRate="48")] public class XMLSlideshow extends Sprite { private var imName:TextField; private var imageHolder:Sprite; private static var count01:Number = 0; private static var _done:Boolean = false; private static var myXML:XML; private static var myTimer:Timer; private static var myURL:String; private var lcs:LoaderClassStatic; private static var _rotation:RotationEffect; private static var _z:Zrotation; private static var _x:Xrotation; private static var _y:Yrotation; public function XMLSlideshow ():void { /* We write the textformat for the headline. */ var format:TextFormat = new TextFormat ; format.bold = true; format.font = "Helevetica"; format.size = 18; /* We create the headline. */ var headLine:TextField = new TextField ; headLine.x = 80; headLine.autoSize = "left"; headLine.border = true; headLine.borderColor = 0xE1E1E1; headLine.backgroundColor = 0xFFFFC6; headLine.text = "Transitioneffect using Flash 10 Matrix3D class"; headLine.setTextFormat (format); addChild (headLine); /* We create a description textfield. */ imName = new TextField ; imName.autoSize = "left"; imName.x = 60; imName.y = 340; addChild (imName); /* We add the main holder for the images. */ imageHolder = new Sprite ; imageHolder.z = 0; imageHolder.x = 80; imageHolder.y = 60; var myBevel:Bevel = new Bevel(imageHolder); addChild (imageHolder); /* We load the XML file. */ var myXML:TextLoader = new TextLoader ; myXML.initText ("menu.xml",completeHandler); } private function completeHandler (e:Event,a:String,b:Number,c:Boolean):void { myXML = new XML(e.currentTarget.data); /* We cycle through the nodes of the XML file. */ var myTimer:Timer = new Timer(400,myXML.sub.length()); myTimer.addEventListener (TimerEvent.TIMER,loadingThumbs); myTimer.start (); } private function loadingThumbs (e:TimerEvent):void { /* We create holders for the thumbs and position them. */ var _mc:MovieClip = new MovieClip ; _mc.name = "_mc" + count01; _mc.x = 75 * count01 + 70; _mc.y = 370; _mc.alpha = 0; _mc.buttonMode = true; _mc.mouseChildren = false; /* We get the URL and name of the slides. */ var slideURL:String = myXML.sub.attribute("slide")[count01]; var slideName:String = myXML.sub.attribute("name")[count01]; _mc.slideURL = slideURL; _mc.slideName = slideName; addChild (_mc); /* We load the images into the imageholders _mc */ var thuLC:LoaderClass = new LoaderClass ; thuLC.initLoader (slideURL,loadingSlides,_mc,null,count01); count01++; } /* The function to load the first image. */ private function firstLoad (event:Event):void { if (! _done) { var myText:String = MovieClip(getChildByName("_mc0")).slideName; imName.text = String(myText); _done = true; } } /* Function when loading of thumbs is complete. */ private function loadingSlides (ev:Event,a:int,b:Object,c:Object):void { /* We need to scale the thumbs and set alpha back to 1. Then we need to load the first image. */ var mc:MovieClip = ev.currentTarget.content.parent.parent; mc.scaleX = 0.2; mc.scaleY = 0.2; mc.alpha = 1; if (a == 0) { myURL = mc.slideURL; lcs = new LoaderClassStatic ; lcs.initLoader (myURL,firstLoad,imageHolder); } /* We create buttons for the thumbs. */ mc.addEventListener (MouseEvent.CLICK,mouseHandler); } /* Function to load slides into an imageHolder when thumbs are pressed. */ private function mouseHandler (ev:MouseEvent):void { /* We need to disable the thumbs here, since pressing a thumb while a transition is taking place would cause serious problems. Mouse response is activated again, once the transition is complete. */ for (var i = 0; i < myXML.sub.length(); i++) { MovieClip(getChildByName("_mc" + i)).mouseEnabled = false; } imName.text = ev.currentTarget.slideName; myURL = ev.currentTarget.slideURL; /* we create an array to randomly have different slide transitions. We have 3 different transitions. The other function parameters are "imageHolder", a MovieClip, which holds the images. Then there is the speed for transitioning (10) and the image url (myURL) and the name of the XML object (myXML). */ var rArray:Array = new Array("x","y","z"); var ranNum:int = Math.random() * 4; _rotation = new RotationEffect ; _rotation.slideTransition (imageHolder,10,myURL,myXML); /* We load different classes for all the effects. */ switch (rArray[ranNum]) { case "x" : _x = new Xrotation ; _x.timerHandler (); break; case "y" : _y = new Yrotation ; _y.timerHandler (); break; case "z" : _z = new Zrotation ; _z.timerHandler (); break; default : _rotation.timerHandler (); } } } }