Web Tools - Generic_mcGraph.swf
Passing Parameters

Most parameters are passed via the ini file - this page describes how to pass additional parameters via the html page.

Overview | FlashVars | JavaScript | Datafile URI | Random Number | Debug Tips

Related pages
Overview | Feature Highlights | Data Format | ini Files | Passing Parameters

Examples
Solar Spectra Time axis - Fixed Time axis - Autoscale


Overview

Most of the parameters used by Generic_mcGraph.swf are read from the ini file. However, there are 2 parameters that can not be passed that way Each of these has a default value (used for testing) - Generic_mcGraph.ini.txt & Default_Data.txt - which is normally overridden by values in the html file (via FlashVars).

Several additional parameters (used to control performance) are also passed this way.

This architecture allows several web pages to be placed in the same directory.

In addition, Generic_mcGraph.swf provides a way for users to select what data to plot (using onclick and JavaScript).


FlashVars

FlashVars is used to pass values to the swf (Flash) file when it is loaded. If you look in the provided example code, you will see the data file and ini file specified via the following 3 commands. Note - 3 commands are needed because of how the interface is implemented. Each of the commands does exactly the same thing, In all, 4 FlashVars properties are supported. The order is not important, separate the properties with ampersands.


JavaScript

The ActionScript 3 ExternalInterface object provides a mechanism for JavaScript (in a web page) to call a function in the Flash application. The following will load a different data file (or query) when the radio buttons are clicked. For this to work, the Flash configuration must allow script access. If you look in the provided example code, you will see that this is enabled via the following 3 commands. The Load_Data function allows any interface object that supports the onclick tag to change the displayed data - the Feature Highlights page provides 2 radio buttons to demonstrate this capability.


Security Issue

There is a small problem with this - when the graph is opened locally (by double clicking the html file), there is an error message (security warning). The message goes on to tell you how to change your security settings so this warning will not be displayed - don't do that, it will open your machine to attacks from other Flash applications. Since there is no failure when getting the page from the web, my suggestion is to open the html page using a local web server.

Since I envision most pages using only a single data file, I have provided a parameter to enable JavaScript callbacks and left them disabled by default. To enable callbacks, add the following to all 3 FlashVars statements.


Datafile URI

The datafile can be a simple text file or a call to a server application that queries a database and returns the result as a text stream with the same format. For this to work, the URI normally includes parameters that specify the query.

For a normal URI, query parameters start with a question mark, are separated with ampersands, and contain equal signs.

However, when a URI is specified via FlashVars, then the ampersand and equals sign characters must be encoded using hex values (because those characters are also used to separate multiple FlashVars parameters). You can use either form with a JavaScript call - they will both produce the same results.

The provided examples only specify simple text files - they do not call a server and do not pass query parameters.


Random Number

When querying data, there is a high probability that cached data will be returned. In English, once a query has been executed, the results will be cached (saved for future reuse). Then, if the same query is requested again, the old, cached, results will be returned. When using a system where the data is changing between query requests, the changes will never be seen. (I have a real time data collection system with this problem.)

There are several way to fix this - when told to, this component adds a random number to the query string.

This is the related ActionScript code.

Note that random=t is the key - the following is converted to something like this (the number is random) and the old cached data will be discarded because the query looks different each time.

As usual, the parameter order does not matter.


Debug Tips

When I use html that is itself produced by a web server, sometimes the swf, ini, and data file URI's require a leading ../


Author: Robert Clemenzi
URL: http:// mc-computing.com / WebTools / Generic_mcGraph / Passing_Parameters.html