After getting good feedback on my first article i decided that I would write a second one. This is wrote as something that can be added onto what was made in the first tutorial I wrote, but it can be used completely separately if you choose. My first article discussed making a skinable interface, this goes one step further by explaining how to list all the skins on a web server, download a preview of the selected skin and display it, and if the user chooses to do so then download the skin. The article I am referring to can be found here http://www.create-games.com/article.asp?id=1124 To achieve this your going to need some objects, I think most of the ones i have used come with MMF, I am not sure about TGF as its been a while since i used it. I think the only extra extension needed will be Supa Supa downloader, this a excellent extension that can be used for lots of useful things. You can download this extension from http://www.pluginx.com/

The first thing i did was to upload some files to my web server, I made 3 zip files, these are the skins for test purposes these just contain a blank text file. I then made 3 preview images (one for each zip) and a ini file so my programme knows what to do with the files from my server. The files are as follows:

skin1.bmp
skin2.bmp
skin3.bmp

skin1.zip
skin2.zip
skin3.zip

test.ini

I should have also added a index.htm into the folder for security reasons.

The file names aren't important providing that the preview image has the same name as the zip. It might be useful to use JPG images as they are smaller in size I only used BMP's for easiness.

This tutorial doesn't explain how to make ini files, there's far far too many article on that if you don't know how to use them you should do a quick search of the daily click articles section. For those that know how they work lets take a look at the ini file i have put onto my web server:

[summery]
filecount=3

[Files]
1=skin1
2=skin2
3=skin3

At the top of the ini is a count of how many files their are on the web server so the programme knows how many items to load in, then under the files list is the name of all the files. Take note, i haven't included any file extensions in the names, I will add either a .bmp or a .zip extension in the code.

Back to MMF I created a frame and added the following:

3 buttons (refresh, preview and download)
File object
string object
counter object with a initial value of 1
and a active picture object

I use the string object so the user knows what the programme is doing, its awful sitting in front of a programme thinking is this working?? has it crashed?? as the zip files may take a few seconds to download this is a useful thing to do.

Lets get started then, firstly i split my code into groups, this is for 2 reasons, 1 to make it easy to read and 2 so i can deactivate certain groups. First group I create is Load List. This group is active at the start, then deactivates once the list has loaded in. It will be reactivated every time the refresh button is pressed. This groups looks like this:

Only once when event loops
Group "load list" is activated

Set string to Display paragraph 1
This is just some text that says "downloading list"

SuprDownload Object - Download "http://www.atnas.com/test/test.ini" to appdrive$ + appdir$ + "test.ini"
This line starts the ini file downloading for my web server to my hard disk. As in my last article appdir$ and appdrive$ are used to ensue it will download to the same folder as the application.

Then a group is added to tell the programme what to do when the file has finished downloading.

Only once when event loops
SuprDownload Object - All files done

I now use the ini object we have just downloaded to set a global variable.

ini - Set current file to appdrive$ + appdir$ + "test.ini"
ini - Set current group to "summery"
ini - Set current item to "filecount"
set - global_server_file_list_count to value of ini

I can now load the list of files from the ini file into the list box in my programme. I call a fast loop to do this.

start "list_files" global_server_file_list_count times

this runs the "load" fastloop once for each file in the list of files lets take a look at the fast loop

on loop "list_files"
ini - set current group to "files"
ini - set current item to Str$(value("counter1"))
list - add lines string of$("ini")
counter1 - add 1 to counter1
string - display paragraph2

so, what's happening in this loop, there's a counter that relates to the file number in the ini, every time the loop goes around the counter gets 1 bigger so it loads the next item from the ini. Str$(value("counter1")) is used to turn the counter from a value to a string so the ini object can understand it. The last action changes the string to say "done" so the user knows the list has been fully loaded

This works nice, but what if something goes wrong what if the user isn't online or something. I add a line that says:

SupaDownload - Something failed
string - Display paragraph 3

Paragraph 3 just says Error, not very constructive but still the user knows something's gone wrong.

last thing to do is to close the group.

global_server_file_list_count = list Nb Lines("listobject")
deactivate group "load list"

this does a quick check, if the list box has X number of items listed in it, and if this is the same as the amount of files in our ini then it closes the group.

Now we have the list loading in ok we can make the reset button work. All the commands for buttons are outside of any groups.

Button "Refresh" clicked
set counter to 1
list reset
file object - delete appdrive$ + Appdir$ + "test.ini"
activate group "load list"

list refresh clears the list box, I use file object to delete the ini so the new one can download. Then the group is activated over again.

Nice, not much left to do now. Just need to make the preview, and download buttons work. The download button is the easiest so we shall do that first. First add some events for the button I create a group called download that's not active at start of frame.

Button "download" clicked
activate group download

Into the download group i add the following:

Only once when event loops
group "download" is activated
string - display paragraph2
supr download - download "http://www.atnas.com/test/" + List Select$( "List" ) + ".zip" to Appdrive$ + Appdir$ + List Select$( "List" ) + ".zip"

this changes the string text, again informing the user its downloading a skin, the super download line tells the object to download the file that's selected on the list, it also adds a .zip extension. Now some code to close this group

spr download - all files done
string - display paragraph 2
Deactivate "download"

That's it, now it will download your skins. The last thing to do is to make the preview option work, this is done almost the same as the download option. So the user doesn't waste loads of hard disk only one preview image is ever needed since the programme only shows them one at once so every preview I download is going to have the same name. The preview group works the same as the download one, its inactive at the start of the programme and is called by a button. The button has a extra line in though to delete the previous preview image.

Button "preview" clicked
file object - delete appdrive$ + Appdir$ + "preview.bmp"
activate group preview

The preview group is as follows:

Only once when event loops
group "preview" is activated

string - display paragraph4
supr download - download "http://www.atnas.com/test/" + List Select$( "List" ) + ".bmp" to Appdrive$ + Appdir$ + "preview.bmp"

this works the same as the download instructions used by the download button except it adds a .zip extension, and always calls the file preview.bmp

supr download -all files done

active picture - new picture : Appdrive$ + Appdir$ + "blank.bmp"
active picture - new picture : Appdrive$ + Appdir$ + "preview.bmp"
string - display paragraph2
deactivate "preview"

In my programme blank.bmp doesn't exist, its in the code because you have to change to picture to update your active picture. I deleted my blank picture as it wasn't needed, this gives a error when you open it in MMF, but works fine when its compiled.

Note: with active objects theres a expression button at the bottom of the box where you choose your image so you can use Appdrive$ and Appdir$ in your path..

That's all their is to it. As you can see the super download object is very useful, with a little working on this code you could come up with something very useful. This time i have included a 8kb source file too so ya can have a quick look at it (http://www.atnas.com/clickstuff/test.zip) and yes I know errors in it, images are missing, thats because the code hasn't downloaded them yet its supposed to be like that if you read the above you will find out why.

One last thing to consider is the bandwidth your host gives you, whilst this isn't a problem if its your own server, if its remotely hosted consider this, you release your app / game what ever on the daily click, say 200 people take the time to download it and have a little play within the first 3 or 4 days of you putting your file up. If your skins are say 150kb each in size, and each user averages 4 skins, thats a extra 120 mb of bandwith used ontop of what ever your original file size is. If you only have a 1gb of bandwith to play with this will EAT it.

I hope this article is useful for some people, I know its a bit on the long side - that's because i have tried to explain as much as possible.

Enjoy
SAnTA
ATnAS.com