Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com�s entire library of video tutorials.
Continuing from the previous movie my review of the scripts required to get your XML-based slideshow operational and working, after initializing our variables which was the last part of the previous movie, we're now ready to initialize the whole slideshow so let's go down now to the next section of script and that's this initialization function right here. Now in this function first we create a new URLLoader for the slideshow XML file, that's this line right here and then we add an EventListener, when the loading event is completed we're going to run this function onXMLLoadComplete. Then we actually load the XML file. We've seen all three of these lines of code previously. Then we create a new Timer with the delay from our TIMER DELAY constant that we established previously. And then we add another EventListener, this time for the TimerEvent, when the TimerEvent is completed we're going to run this switchSlide function, that's the most important function in this movie that I'll be covering. Then we create two container Sprites which will hold the slides. Notice that we've set up variables previously for these two containers, right here, those are the slide holders. Now we actually create them here using this line of code: sprContainer1 equals new Sprite, that's instantiating a new object there, then we're placing those objects on the display list, actually on the Stage right here. Add with the addChild method. We've seen that script before as well. We're also keeping a reference of the container which is currently in the front. We start off with sprContainer2 in the front; later on there'll be another function for switching those back and forth. As I mentioned previously, once our XML file is fully loaded then we call the function onXMLLoadComplete, that's the next function here in the script. Let's review both of these functions now. This function, the onXMLLoadComplete assigns the received data into the XML slideshow, gets the total slide count and then stores it in the variable, intSlideCount, our initial slide count, right here. I'm creating the XML Slideshow from a new XML call right there. There's that funny parameter there in the function e.target.data, which I've covered previously. Here's the total slide count: intSlideCount equals xmlSlideshow.image.length, that's the method length there for getting the length of that slideshow. Here we've switched the first slide without a delay. Notice that I'm running this switchSlide function then, the parameter is null. Again, close off your functions with the closing curly brace. The next function is the fadeSlideIn. This will be called once the picture is fully loaded. First we added the loaded slide from the slide loader to the current container, then we fade the current container with the Caurina's Tweener engine right here, there's that custom class that we used, capital T in the Tweener. There are the parameters for that class there that we need to call. Let me go ahead and put this on two lines so you can read all of it: Tweener.addTween open parentheses currentContainer comma then another set of parentheses alpha:1 comma time, so on. So there's that entire call to that custom class that we're using. This part of the script creates an endless loop which will switch the slides back and forth from container 1 to container 2. Now we're finally ready for that switchSlide function, probably the most important function in the script. Let's go ahead and move this over so we can see it: function switchSlide, this is a very large one so it won't fit in one screen's worth. This function will be called every time the Timer has reached the delay and triggers the TimerEvent, so first of all we check if the Timer's running and then stop it because we need to wait until the next slide will be loaded and faded in. Notice this is done with a conditional: if slider running then slider.stop, watch the syntax there. Then we check if there are any slides left; if not, we go back to the beginning right here. If the intCurrentSlide plus 1 is less than the intSlideCount, if so than increment that number, so we show the next slide, if not then start over at the beginning. Notice that intCurrentSlide equals zero, that represents slide number 1, remember. Next, we need to figure out which container is currently in the front and then assign the current container to that one. So we have currentContainer equals sprContainer2, then go ahead and set it to number 1 else set it to number 2, so that's going to be switching the containers back and forth between 1 and 2.
| Course: | Adobe Flash ActionScript 3.0 for Designers |
| Author: | James Gonzalez |
| SKU: | 34060 |
| ISBN: | 1-935320-82-3 |
| Release Date: | 2009-11-09 |
| Duration: | 9.5 hrs / 101 lessons |
| Work Files: |
Yes |
| Captions: | No |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |