Flash Goddess Forum Index

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SlideShow Revisited

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Flash Goddess Forum Index -> Tutorials
View previous topic :: View next topic  
Author Message
Warangel



Joined: 22 Jul 2002
Posts: 928
Location: Toronto

PostPosted: Wed May 14, 2003 3:37 pm    Post subject: SlideShow Revisited Reply with quote

If you remember our “Flash Remoting in under Ten Minutes” tutorial, you may have an idea of what this new tutorial is about.

The source files for this tutorial can be found at:
http://www.flashgoddess.com/tutorials/slideShowRev.zip

In our first Remoting tutorial we created a slideshow, which retrieved the image names from a database, then looked in an “images” folder for those images.

After giving this some thought, I realized it is not the most efficient way to do this. After all, why enter in data twice when we have the ability to enter it only once? Today, we are going to learn about CFDIRECTORY, which will scan our images directory for us, returning every name it finds in that directory to us in Flash as an array. At that point, we simply use our existing SlideShow script to play the show.

PART 1 A Better Backend

What could be better than none? We have no database, and therefore no backend. No DSN usage. There is nothing at all to do here. I like this already.

PART 2 Minimal Middleware

Because there is no backend database to deal with, we can significantly reduce the amount of code we use to retrieve our information.

We begin this tutorial by creating our CFC, named slideEngine.cfc. We are going to have one function, as before, only this one is maximized for performance:

Code:

<cfcomponent>
<cffunction name="slideProvider" access="remote">


This is the magic. We simply tell CFMX what directory we would like it to scan, and it will put every item it finds into an array by name.

Code:

    <cfdirectory directory="C:\Inetpub\wwwroot\slideShow\images"
          name="myDirectory"


We also throw in a date sort for fun, so that new images will always be added to the end of our slideshow.

Code:

          sort="datelastmodified ASC">

    <cfreturn myDirectory>
  </cffunction>
</cfcomponent>


PART 3 Familiar Frontend

For the most part, our front end remains untouched. We still connect to our service as we always have in Remoting, and our slideShow functionality is the same. The only difference we make is how we access the data.

Code:

#include "NetServices.as"
#include "NetDebug.as"
//#include "Dataglue.as"

// initialize your Flash Remoting connection
if (inited == null) {
   inited = true;
   NetServices.setDefaultGatewayUrl("http://localhost/flashservices/gateway");
   gateway_conn = NetServices.createGatewayConnection();
   // establish your CFC as a service
   myService = gateway_conn.getService("slideShow.slideEngine", this);
   // call that service once a connection has been made to start the slideshow
   myService.slideProvider();
}


This is the function we are modifying. This time we access the image through its name property from our Result object.

Code:

function slideProvider_Result(result) {
   var imgURL = "images/"+result.items[0].name;
   imageHolder.loadMovie(imgURL);
   thisImage = setInterval(showImage, 7000, i=1);
   function showImage() {
      imageHolder.loadMovie("images/"+result.items[i].name);
      if (i<result.items.length-1) {
         i++;
      } else {
         i = 0;
      }
   }
}

// create the MC to hold the images
_root.createEmptyMovieClip("imageHolder", 1);

// offcenter it to be special
imageHolder._x = imageHolder._y=20;


And that’s it. It works the same as before, only now, instead of having to put an image in the appropriate directory AND entering the name into a database, we just put our image in the correct directory, and we are ready to go.
_________________
Marcus J. Dickinson
I believe

* do NOT private message me your questions please. Post them on the board, so that all may benefit. Thank you.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Chesil



Joined: 14 Jun 2003
Posts: 1

PostPosted: Sat Jun 14, 2003 10:40 am    Post subject: Missing zip file Reply with quote

The link to the source code zip file seems to be bad.
Back to top
View user's profile Send private message
Flash Goddess
Administrator


Joined: 18 Jul 2002
Posts: 1228
Location: Ontario, Canada

PostPosted: Sat Jun 14, 2003 11:08 am    Post subject: Re: Missing zip file Reply with quote

Chesil wrote:
The link to the source code zip file seems to be bad.


Try this link:
http://www.flashgoddess.com/tutorials/slideShowRev.zip
_________________
:: FAQ :: Search :: Books :: Tutorials ::
www.FlashGoddess.com :: inspire :: create ::
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Flash Goddess Forum Index -> Tutorials All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Google
 




Powered by phpBB © 2001, 2005 phpBB Group