AS3 Tutorial: Creating a Slideshow

by Armand Niculescu Email
  • Currently 3.73/5
  • 1
  • 2
  • 3
  • 4
  • 5
  • i

Some of my old friends keep asking me for tips and tutorials for flash and actionscript, so I decided to spend a few hours writing a small tutorial for a small slideshow class. The tutorial turned out to be rather long, because I wanted to go in detail and explain the "why", not just the "how".

site using the slideshow

The code is AS3 and the tutorial assumes some general knowledge of flash and actionscript 1 and 2.

Follow up:

The table of Contents is as follows:

  1. Class usage
  2. Loading and parsing the XML
  3. Loading the images
  4. Adding to Stage
  5. Animating
  6. Finishing Touches
  7. Complete Code and Downloads

Class usage

We’re aiming for simplicity here, so reducing the code to minimum, to create a new slideshow, you’d write this in a new .fla frame:

ActionScript 3.0:

var slideshow:Slideshow = new Slideshow("list.xml");
addChild(slideshow);

The first line should create an instance of the Slideshow class, while the second one would simply add it to the Stage (no more attachMovie!).

Therefore, the barebone structure of our class will look like this:

ActionScript 3.0:

package
{
        public class Slideshow extends Sprite
        {
                import flash.display.*;
 
                public function Slideshow(datasource:String)
                {

                }
        }
}

Doesn’t really do much for now, does it?

As you can see, in AS3 we need to specify the package for the class. If you’ve worked with packages in AS2, instead of writing something like

class com.widgets.Slideshow
{
...

you now write

package com.widgets
{
	class Slideshow
	{
...

In this tutorial we won’t be using fancy packages, because the Slideshow is not part of a bigger framework – although you’re free to integrate it in one.

Note how we’re importing the flash.display package so we can extend the Sprite class. By the way, Sprite is a new kind of MovieClip without timeline (technically MovieClip extends Sprite by adding timeline functionality) but the point is that if you don’t need your clip to have multiple frames, you’re better off with a Sprite as it uses less RAM.

On the next page, we’ll see how to load and parse the xml that contains the image list.

Pages: 1 · 2 · 3 · 4 · 5 · 6 · 7

No feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
This is a captcha-picture. It is used to prevent mass-access by robots.
Please enter the characters from the image above. (case insensitive)

This is the blog of the Media Division team. We're giving back to the community some of the things we have learned while building all sorts of apps. Concentrating on Flash/Actionscript, we'll also cover C#, MSSQL, ColdFusion/Oracle and areas like Photography and design. We're writing original articles only - no silly stuff to generate more traffic.

Search

XML Feeds

Aggregated by MXNA

Aggregated by MXNA

Related Links