Animated GIF in a Layout Control
Q. How do I put an animated gif into an ActiveX layout.
A. You can't. I don't know why but all of the image controls I have come across will do nothing with an animated GIF except show the first frame.
Don't dispair with a little coding you can easily get around this.
The first thing you need to do is create your images. You should already have these if you have created a real animated GIF. Failing that you can usually save the individual images from an animated gif by opening up an animated gif in one of the GIF animator packages kicking around on the web.
Here are the ones I am going to use.
Having rounded up you images by whatever means the next thing you need to do is insert an image control into your layout. This method will work with the standard Image control but the one I'm going to use here is the new IPTD Image Control which is used at the sitebuilder site. If you don't yet have this one all you have to do is go to ...sitebuilder... and it will be automaticaly downloaded to you machine.
Here comes the coding. First Declare a couple of variables. Then you need to download all of the images to the cache. This is done in the Layout_OnLoad routine by calling the Ld routine.
|Dim TimerCount |
Imgdir = "http://buster/sbn/animgif/"
Call Ld(SI1, "bgrnd1.gif")
Call Ld(SI1, "bgrnd2.gif")
Call Ld(SI1, "bgrnd3.gif")
Call Ld(SI1, "bgrnd4.gif")
Call Ld(SI1, "bgrnd5.gif")
Call Ld(SI1, "bgrnd6.gif")
Call Ld(SI1, "bgrnd7.gif")
Sub Ld (obj, pic)
Set lobj = obj
lobj.LoadPictureToCache = Imgdir + pic
Note that the full url of the image must be specified and that the first piture is set on the control.
The next thing is to specify when the images are displayed. This is easily done with a timer routine. For simplicity I am going to specify a timer interval of 500 ms which is half a second. This is easily done in CPad but if you do not have access to CPad then you can change the line <PARAM NAME="Interval" VALUE="500"> following the IeTimer object declaration.
|Sub IeTimer1_Timer() |
TimerCount = TimerCount + 1
Select case (TimerCount)
Case 1 Call Show(SI1,"bgrnd1.gif")
Case 2 Call Show(SI1,"bgrnd2.gif")
Case 3 Call Show(SI1,"bgrnd3.gif")
Case 4 Call Show(SI1,"bgrnd4.gif")
Case 5 Call Show(SI1,"bgrnd5.gif")
Case 6 Call Show(SI1,"bgrnd6.gif")
Case 7 Call Show(SI1,"bgrnd7.gif")
Case 8 TimerCount = 0
Sub Show (obj, pic)
Set lobj = obj
lobj.picture=Imgdir + pic
This code will display the images over and over again. If you only want to show the animation once then you could use the following code.
| Case 8 IeTimer1.Enabled = 0 |
That is all of the coding you should need. The only other things you need to specify are the objects themselves. Click here to see the complete .ALX listing.
When the layout is loaded you should see the following pseudo animated GIF.
The advantage of using an ActiveX Layout to animate a GIF is that you have some control over the speed at which it replays. Try sliding the grey button in the following layout left and right.
© 1997 Chris Bayes For ClubSBN. All Rights Reserved.