Task: JavaScript-Controlled Slideshow

I l @ ve RuBoard

Here's a task that can be performed easily with JavaScript, provided that the user has the right browser. In this task, we'll build a movie that doesn't have much of any ActionScript in it at all. The JavaScript on the HTML page, however, controls it completely.

  1. Create a new Flash movie with three or more different frames in it. It doesn't matter what is on each frame, as long as you can easily tell the difference between frames .

  2. Place a stop() command on the first frame so that the movie doesn't animate.

  3. Publish the movie with a standard HTML page. There is no need to use the Flash with FSCommand template.

  4. Using a text editor, open the HTML page.

  5. Add an ID parameter to the OBJECT tag and a NAME parameter to the EMBED tag. Use "slideshow" as the value for both.

  6. Also add an swLiveConnect=true to the EMBED tag.

  7. Add two buttons to the HTML page. Use this code:

     <FORM NAME="flashControlForm"> <INPUT NAME="next" TYPE=Button VALUE="Next" onClick="nextFrame();"> <INPUT NAME="prev" TYPE=Button VALUE="Previous" onClick="prevFrame();"> </FORM> 
  8. These two buttons call one of two functions. They both use TcurrentFrame("/") to get the number of the current frame and then GotoFrame to go to either the next or previous frame in the movie.

     <SCRIPT LANGUAGE="JavaScript"> function nextFrame() {   var frameNum = window.document.slideshow.TCurrentFrame("/");   window.document.slideshow.GotoFrame(frameNum+1); } function prevFrame() {   var frameNum = window.document.slideshow.TCurrentFrame("/");   window.document.slideshow.GotoFrame(frameNum-1); } </SCRIPT> 

Test your movie or use the files in the 17slideshow folder. The handy thing about this technique is that you can easily substitute any Flash movie and it instantly makes a slideshow presentation out of it. You'll either need to put a stop() at the start of the movie or add a play=false parameter in the tags so that the movie does not advance past the first frame when it starts.

I l @ ve RuBoard


Sams Teach Yourself Flash MX ActionScript in 24 Hours
Sams Teach Yourself Flash MX ActionScript in 24 Hours
ISBN: 0672323850
EAN: 2147483647
Year: 2002
Pages: 272

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net