ActionScript 2 Cross Fading XML Slide Show

A class based cross fading slideshow for ActionScript 2. Class file now supports captions which can be set to display persistently or only via a rollOver event. Captions use an embedded font, (contained in zip archive), however you are free to change this font or use device fonts. Look in the class variable declarations for what variables you can set. You can now (as of v 1.4) use multiple instances of the class in your swf.

SlideShow Features
By Editing the XML file, you can;

    Specify cross fade time.
    Specify image duration.
    Specify image sequence order.
    Specify Captions
    Specify Persistent Captions

The class file takes one parameter in its constructor, which where you want the slideshow to appear.
By editing the class variables you can;

    Specify Font
    Specify Font Colour
    Specify Font Size
    Specify the use of embedded fonts
    Specify Text background colour and alpha
Example

You can preview the files here;?Ǭ†http://www.noponies.com/dev/simplecross

Source Files

Get the files here; Demo Source Files

Old Non Captions based Files here; Simple Cross Fading Class Source Files

Dependencies

Class uses the excellent TweenLite class from greensock, which you can obtain from here;?Ǭ†http://blog.greensock.com/tweenliteas2?Ǭ†?Ǭ†(class file is included in .zip download)

Updates

23 Feb, 2008: Updated class with new methods, one ensures no duplicate slides are shown one after the other when using the random mode. The other is a public method that you can call when deleting one slideshow and replace it with another using the same generic holder var. This method kills the currently running interval (well it should). Class now takes another parameter in the constructor, which is the path to the XML file you want to use. This lets you use multiple instances of the class in your swf.

42 Neighs about “ActionScript 2 Cross Fading XML Slide Show”



Alex Neighed:

We’re finding a race condition with this where if you unload the movie, before the image has loaded the setInterval is never cleared.

Because setInterval seems to be a persistant (nuisance) object, it stays around so when we load the script again for a second slide show you get a ‘jump’ effect of the pages flickering as the first setInterval comes back to call the fade images function as well.

Really annoying! Bar using onEnterFrame instead (which we’ve done) or having a clearInterval on start to make sure there aren’t any rouge setInterval processes running before we start, any other thoughts on a good work around for this?

Dail Neighed:

Hi Alex,

OK, I’ll have a look at the class again to see what can be changed.

Dail Neighed:

Alex,

I’ve added in a new method “killInterval()” which you can call prior to loading in a new slide instance, this will kill the interval running, if there is one running. Seems to work OK in the testing I have conducted. The class has a few new methods as well, and now takes the path to your XML as a constructor param, so you can use more than one slideshow in your swf.

Josh Neighed:

Hi Dail! Great work man. Is there a way to link each image to specific url in the non caption version? Thanks!

Dail Neighed:

Josh,

You will simply have to add a onrelease function to either the container clip, or to each image in the movieClip loader init handler. Then I guess you would use (if you provide a specific URL for each image in the XML file) array access, using the p var. So a click would run a getURL(yourListOfURLSArray[p]), or something like that. A bit of work as that functionality is not built in.

Bboran Neighed:

var slide:simpleSlideCaptions = new simpleSlideCaptions(”your_movieClip_name”, “someXML.xml”);

this is not working. it gives Type mismatch error all the time

Dail Neighed:

var slide:simpleSlideCaptions = new simpleSlideCaptions(this, XMLFIle);

Take out the quotes around the movieClip name.. So it looks like this; slide2 = new simpleSlideCaptions(slide2_mc, “images2.xml”);

Bboran Neighed:

ok now it works but it does not fit to my mc, it expands from the mc. how can i fit it to my mc? for example my images are 750*200 pixels and i made the container mc 750*200 too. but the image starts from the vertical center of the mc.

Dail Neighed:

Check your registration point in your movieClip that you are loading the slides into. The slides will position themselves based off that movieClips registration point. You want it to be at the top left, or 0, 0.

Bboran Neighed:

ok now it works but there i found a new bug. when i set the order to random in xml file. the images comes randomly but the captions are not. it always showing the first images caption for all the images.

Bboran Neighed:

and also in the ordered mode the captions are displaying as ;
for the first image it display the second images caption,
for the second image it displays the third images caption etc…

Dail Neighed:

strange, I’ll look into it.
OK, found the error and fixed it. It should be fixed for both ordered and random captions display now.

Bboran Neighed:

no not yet, now it shows the caption bar without any text.

Dail Neighed:

Strange, I added in another fix. Its working fine when I test it here. Try it again….

Dail Neighed:

Yep, that and the Class As in the post above.

Bboran Neighed:

can you please share your demo file with the sources ,cause i cant get it work

Bboran Neighed:

it gives me now;
The name of this class, ’simpleSlideCaptions’, conflicts with the name of another class that was loaded, ’simpleSlideCaptions’.

Dail Neighed:

The source files are all there. If you are looking at the demo online, make sure you clear your browsers cache, for it to load in any changes to the XML

Dail Neighed:

Odd,

Here is how it works with two instances of the slideshow – timeline code..

var slide:simpleSlideCaptions = new simpleSlideCaptions(this, “images.xml”);

//load in a slideshow with a button click
var slide2:simpleSlideCaptions

slide2_mc.onRelease = function(){
if(slide2!=undefined){
slide2.killInterval()
}
slide2 = new simpleSlideCaptions(slide2_mc, “images2.xml”);
}

Jen Neighed:

Quick question. Where in the As do I move the caption text field?

Dail Neighed:

Jen,

captionsHolder._y = holder_mc._y+holder_mc._height-captionsHolder.captionsHolderBg._height;//bottom align text//adjust here if needed pos of text

Adjust that line of AS

George Neighed:

Hi Dail,

I have a similar problem with Alex but more complicated. I’m working on a flash website where there are many swf movies used together. There is an index.swf which loads a swf movie in level10 for each category (events, contact, profile, etc). Then, each level10 movie loads 1 or more swf movies using the xml slide show.

Unfortunately, if you change the level10 movie and get back you can see “jumps” in slide show. Tne gallery movies are nested in a level10 movie and the level10 movie in turn is loaded in the index.swf.

I’ve uploaded an example at http://www.g4vr.com/files/dev_test.zip

I know that I have use the kill interval function but my case is more complicated as I have nested swfs. Maybe a clear interval on start is the solution. Any thoughts on a good work around for this?

keep up the good work

George

Dale Neighed:

George,

Interesting. Have you simply tried changing XML files for each section?

You can try to clear the interval on load. That may help. Timers in AS2 like to hang around however. If I get a chance I’ll look at your file. But I’m snowed under at the moment.

Derlei Neighed:

Hi Dail

thanks for this nice cross fader

But can you explaine me how can add a link to the image itself rather than

reference links in the cdata tags?

Richie Neighed:

I’m not very advanced in actionscript. What is the best way, if at all, to begin to incorporate buttons or a controller for the slideshow?

Thanks!

anthony Neighed:

I was wondering where in the script I can change to make the images not repeat until after all the images have been displayed (eg. in a pool of 10 images, no repeats until the 11th image, then again at the 20th). Thanx in advance.

Kenet Neighed:

I am still learning actionscript so I was wondering is it possible to apply a Mask to this slideshow?

I want to play the slideshow within a masked area. Is this possible?

Dale Neighed:

Kenet,

I don’t see why not. Give it a go.

John Neighed:

Thanks for sharing this really handy great slideshow! It’s working for me with the exception that the fonts are not displaying as intended. I see only a very small device font with wide gaps bewteen words. So far i have tried adding a new Font embedded in the Library, and changed the .as file accordingly – but same result. Am using PC, Flash CS3. Thanks for any tips!

EliB Neighed:

Hi

I tried the class in my application and it works great….

Since I do not know in advance the size of the images I am loading through the xml, I want to use a “movie_clip_fit” method after I load the images and, so I think, before the tween.

When I use a MovieClipFit command there is a “jump” in the display.
Maybe I am putting it in the wrong place ???

This is how U implemented it :

private function loadSlides() {
//sequential loading of images
holder_mc.createEmptyMovieClip(”bg_loader”,2);
slideLoader.loadClip(bgImages[p],holder_mc.bg_loader);

MovieClipFit.fit(holder_mc.bg_loader,some_width,some_height);
p++;
if (p == bgImages.length) {
p = 0;
}

}
I am not using the randon option. and not the caption options so I dont need the getUniqueNum function.

Thanks for a hint….

Eli

Spin Neighed:

This is absolutely fantastic! Thank you, that certainly deserves a Donation.

BrotherEye Neighed:

Does anyone know if this can be made to work with transparent PNGs? Fantastic work. Thanks.

Cyn Neighed:

This is great and (I think) just what I need. Thanks. But I have a ActionScript newbie question:
I would like to combine 2 slideshows running side by side, running independent intervals and imgaes. I set this up with 2 different XML files and 2 separate instances of the MCs and modified the AS to point to them but how do I get them to point to separate XML files. Seems like it should be easy…

Dale Neighed:

BrotherEye,

I’m not sure. I’ve never tried it. I don’t see why it would not work though.

Cyn,

simpleSlideCaptions(slideTargets:MovieClip, xmlData:String)

Just pass in the two different XML files to the class constructor.

Cyn Neighed:

Got it! This is awesome. Thanks for your help.

Trillion Neighed:

Hi Dale

Thanks so much for all the tutorials you’ve put online – sooo helpful!! I love no ponies

I really like this slide show, just one problem I’m experiencing:
I’ve made a website that when the user clicks each navigation link, it loads in each page/swf externally, in to the main interface.

I’ve put this slide show in the “About Us” page/swf. It works beautifully until I view another page, and then view “About Us” again, in the same sitting, the interval doesn’t seem to clear or be cancelled, and I’ve tried using your “killInterval()” function but doesn’t seem to work the same way as having two slide shows on one page?

There will be a 2nd slide show on another page of the site too, but I’d like to be able to clear the intervals of these in a way that allows for viewing the slideshow pages over and over without the intervals overlapping.

Let me know if this doesn’t make sense :)

Thank you! much appreciated!

T

Alex Neighed:

Hi Dale

Forgot to say thanks for fixing the setInterval stuff and a really nice slideshow and code – many thanks again :-)

Alex

Tira Neighed:

Hi there!

Excellent work! I’m learning Actionscript and your site has been so very helpful. Thank you!

Is it possible to place another text field above the caption, like a title field?

Also, I moved the text box around a bit and am using an html font instead of the embedded font and the text doesn’t fade out smoothly. Do you think it might be because of the html text?

Thank you so much!

Dale Neighed:

Tira,

Sure, just follow how the description field works, duplicating it, but for your title.

Alpha fading embedded text can look a little funky, not much you can do about that really.

joel Neighed:

Is there a way to add static elements over the images. For example if you wanted to add a frame to the movie or a logo over the top? I tried to add the elements to a layer on-top of the actionscript layer but that didn’t work.

Thanks.

joel Neighed:

oh … never mind … i just loaded an external movie with all the “frame and logo” stuff. Just loaded it to level999. Works great.

Leave a neigh?