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
- The name of the ini file
- The name of the data file
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.
'FlashVars','Filename=Temp_RH_Data_short.txt&ini=Example_Time_Auto.ini.txt',
<param name="FlashVars" value="Filename=Temp_RH_Data_short.txt&ini=Example_Time_Auto.ini.txt" />
FlashVars="Filename=Temp_RH_Data_short.txt&ini=Example_Time_Auto.ini.txt"
|
Note - 3 commands are needed because of how the interface is implemented.
Each of the commands does exactly the same thing,
- The 1st is used if JavaScript is enabled
- The 2nd is for IE without JavaScript
- The 3rd is for Netscape (Mozilla) without JavaScript
In all, 4 FlashVars properties are supported.
The order is not important, separate the properties with ampersands.
Option
| Description
|
---|
Filename
| Used to specify the initial data - can be a filename or the
name of a program and its query parameters
|
ini
| Name of the ini file
|
GraphTitle
| An alternate title for the graph
|
Refresh
| Including this displays a refresh button that re-executes the last query
|
callbacks
| Enables the JavaScript callback capability
|
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.
<script language="javascript">
function Load_Data(mcGraph_Datafile)
{
document.getElementById("Generic_mcGraph").PlotData(mcGraph_Datafile);
}
</script>
<br> <input type="radio" name="data" VALUE="1"
CHECKED
onclick="Load_Data('Temp_RH_Data_short.txt')">Default (25K - Fast to load)
<br> <input type="radio" name="data" VALUE="2"
onclick="Load_Data('Temp_RH_Data.txt')">Alternate (152K - About 6 seconds to load)
|
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.
'allowScriptAccess','sameDomain',
<param name="allowScriptAccess" value="sameDomain" />
allowScriptAccess="sameDomain"
|
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).
Adobe Flash Player has stopped a potentially unsafe operation.
|
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.
http://localhost/Generic_mcGraph/index.html
|
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.
SomeProgram.exe?name1=value1&name2=value2
|
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).
& %26 This delimiter must be encoded
= %3d Testing indicates that this substitution is not necessary
'FlashVars','Filename=SomeProgram.exe?name1=value1%26name2=value2&ini=Example_Time_Auto.ini.txt',
|
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.
if (f.indexOf("random=t")>0){
f += "&a=" + Math.random();
}
|
Note that random=t is the key
- the following
SomeProgram.exe?name1=value1&name2=value2&random=t
|
is converted to something like this (the number is random)
SomeProgram.exe?name1=value1&name2=value2&random=t&a=0.3426547
|
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 ../
DataFile.txt vs ../DataFile.txt
|
Author:
Robert Clemenzi