Link Management with Databank

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)
Loading ... Loading ...

Have you ever wanted to update the links on your website without having to re-edit the .swi file, export it and then upload the revised html and .swf files to your web site? Databank can be used to store the configuration details or other textual data for your website. Website configuration changes can then be made using a simple configuration page that updates and saves the configuration details.

For example, the combo component below is configured from values stored in Databank. Selecting any item from the combo will open the associated page in a new browser window or tab (depends on default browser).

Now to manage these links we open a configuration page. The configuration data and the example configuration page is shown below:

When loaded, the configuration page shows the currently configured data. The data can then be modified and updated using the Update button. The update only occurs when the user entered password matches the password that is stored in the Password parameter for the page. This provides some security against unauthorized alterations.

Downloads

The SWiSH Max4 example files can be downloaded here. The zip file contains examplelinkcombo.swi, examplemenu.swi and examplelinkconfig.swi.

To use the files you will need to setup a free Databank account. This will provide you with a Databank Account Access Key which is required to configure the files.

To simplify use, the example files have been equipped with a wizard interface. To use the files, simply enter your Databank Account Access Key into the Account Access Key wizard parameter for each file and re-save the .swi files.

examplelinkconfig.swi

Once configured, play this file first in Max4. This will create the databank data area and allow configuration of the navigation links.

The password that is entered into the password field must match the password that is configured in the wizard parameters (the default password is “mypw”). If the password does not match, the data currently stored in Databank will be re-displayed when the Update button is pressed.

The data entered depends on the file used: examplelinkcombo.swi or examplemenu.swi.

Configuration for examplelinkcombo.swi

The data is assumed to be one item per line with each item being a comma separated list. The first value in the list is the name that appears in the combo box, the second value is the URL that is to be loaded. The third value is the name of the frame. Use _blank for a new browser window, _self to have the loaded URL replace the current document or swf to load a swf movie into a holding movie clip.

For example:

SWiSHzone.com,http://www.swishzone.com,_blank
mySWiSHzone,https://my.swishzone.com,_blank
Forums,http://forums.swishzone.com,_blank

Adds items SWiSHzone.com, mySWiSHzone and Forums to the combo box. These items open the URLs: http://www.swishzone.com, https://my.swishzone.com and http://forums.swishzone.com in a new browser window as _blank was used as the frame reference.

Configuration for examplemenu.swi

Enter the menu definition as required by the Menu component. As the links are processed by the Events function, it is not necessary to precede URL references with “URL:”

For example:

News=http://www.abc.net.au/news,_blank;
SWiSHzone.com=
{
 Main=http://www.swishzone.com,_blank;
 Blog=http://blog.swishzone.com,_blank;
 Forums=http://forums.swishzone.com,_blank;
 mySWiSHzone=https://my.swishzone.com,_blank;
}
Other=
{
Weather=
{
BOM=http://www.bom.gov.au,_blank;
WaterTemp=http://mhl.nsw.gov.au/www/wave_temp.htmlx,_blank;
Ski.com=http://ski.com.au/snowcams/index.html,_blank;
Thredbo=http://www.thredbo.com.au/weather-and-conditions/snow-report/,_blank;
}
Entertainment=
{
IMDB=http://www.imdb.com,_blank;
TV Guide=http://www.yourtv.com.au/guide/,_blank;
Youtube=http://www.youtube.com,_blank;
}
}

Is the configuration for the sample menu shown above. _blank, _self and swf behave in the same way as described previously.

Analysis

The script for the examplelinkconfig page is shown below:

function Events(n,v) {
 // button pressed. write the current data
 if (parameters.Password == pwd.text) {
 databank.SetData(1, parameters.DatabankItem, config.text);
 } else {
 databank.GetData(1, parameters.DatabankItem);
 }
}

function DataEvents(n,v) {
 switch(v) {
 case 0:
 // request current config
 databank.GetData(1,parameters.DatabankItem);
 break;
 case 1:
 // show current config
 config.text = databank[parameters.DatabankItem];
 break;
 }   
}

The Events function is called when the Update button is pressed. The DataEvents function is called when the databank component receives data.

The basic flow is as follows:

When the databank component is loaded, it calls the DataEvents function with v=0. This initiates a request for data. The requested item is defined by the wizard parameter: parameters.DatabankItem.

When the data is received, the DataEvents function is called with v=1. The config text object is then updated with the received data that was stored in the databank component (datbank[parameters.DatabankItem]).

When the Update button is pressed, the Events function is called. If the password entered into the pwd text object matches the wizard parameter parameters.Password then the revised data from the input text object config is sent to databank via the SetData() method. If the password does not match, then the original data is re-read using GetData.

The script for the examplelinkcombo page is shown below:

function Events(n,v) {
 var sel = Combo_silver.GetCurSel();
 if (sel < 1)
 return;    // no selection
 sel--;    // decrement as array is 0 indexed
 if ("swf" == lineData[sel][2]) {
 // load .swf file into holder
 holder.loadMovie(lineData[sel][1]);
 } else {
 getURL(lineData[sel][1],lineData[sel][2]);
 }
}
function DataEvents(n,v) {
 switch(v) {
 case 0:
 databank.GetData(1,parameters.DatabankItem);
 break;
 case 1:
 // configure combo
 lines = databank[parameters.DatabankItem].split(chr(13));

 var list=parameters.DefaultComboItem;
 // trace(lines.length);
 for (var l=0;l<lines.length;l++) {
 lineData[l] = lines[l].split(",");
 if ("" != lineData[l][0])
 list = list add ";" add lineData[l][0];
 }

 Combo_silver.SetItems(list);
 break;
 }
}
onSelfEvent(load) {
 var lines;
 var lineData = new Array();
}

On loading, global variables lines and lineData are defined to hold the received data.

The Events function is called when the Combo_silver object is altered. The DataEvents function is called when the databank component receives data.

When the databank component is loaded, it calls the DataEvents function with v=0. This initiates a request for data. The requested item is defined by the wizard parameter: parameters.DatabankItem.

When the data is received, the DataEvents function is called with v=1.

The received data stored in datbank[parameters.DatabankItem] is then split into lines. The lines are then split into fields and placed into the lineData array. The Combo_silver has its item list set according to the first field of each item via the method SetItems().

When the combo object is altered, the Events function is called. If the selection is other than the first item the data from the lineData array is retrieved and the appropriate URL or SWF movie is loaded.

The script for the examplemenu page is shown below.

function Events(n,v) {
 var lineData = v.split(",");
 if ("swf" == lineData[1]) {
 // load .swf file into holder
 // trace("load movie:" add lineData[0]);
 holder.loadMovie(lineData[0]);
 } else {
 getURL(lineData[0],lineData[1]);
 }
}

function DataEvents(n,v) {
 switch(v) {
 case 0:
 databank.GetData(1,parameters.DatabankItem);
 break;
 case 1:
 Menu.SetMenu(databank[parameters.DatabankItem]);
 gotMenu = true;
 break;
 }
}

onSelfEvent(load) {
 var gotMenu = false;
}

onFrame (1) {
}

onFrame (2) {
 if (!gotMenu)
 gotoAndPlay(1);
}
onFrame (5) {
 Menu.Display(1);
 stop();
}

On loading, global variables gotMenu is set to false indicating that the menu configuration has not been received.

The Events function is called when the Menu object is pressed. The DataEvents function is called when the databank component receives data.

When the databank component is loaded, it calls the DataEvents function with v=0. This initiates a request for data. The requested item is defined by the wizard parameter: parameters.DatabankItem.

When the data is received, the DataEvents function is called with v=1.

The received data is used to configure the menu via Menu.SetMenu(databank[parameters.DatabankItem]) and gotMenu is set to true indicating that the menu has been configured and is ready for display.

The onFrame (1), onFrame (2) and onFrame (5) events form a loop that displays the menu once the menu has been configured. A short delay is given before display to allow the menu component time to duplicate the internal movie clips.

Notes

For security reasons we recommend that you place the configuration page in a password protected area of your website. Ideally, communications with the configuration page should be via a https link.

We do not guarantee that data placed in Databank is 100% secure. Consequently it should not be used to hold data that is intended to be private.

Tags: , , ,

3 Responses to “Link Management with Databank”

  1. Keith Jones says:

    Is the visual effect of the menu as above available as a swi?

    • jonh says:

      Both of the examples are included in the example files downloadable zip file.
      I applied filters to the standard menu component to achieve the shadow and bevel effects.

      Jon

  2. Keith Jones says:

    Thanks Jon – I will have to look at it more carefully.

    Keith


Switch to our mobile site