Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use a Perl script to automate Flash content Internet
I hapen to like some aspects of Flash's interface ability and design. But it is very hard, and not very well documented, regarding how to have Perl manipulate Flash. I wanted a Flash site that could automaticly search my directories for PDF content of stories, poems, etc. So I looked into how Flash loaded external variables, and then made a Perl script (and several other 'glue' pieces) to force Flash and Perl to work together.

Please note: This is very buggy, and prone to some very strange errors at times. Mostly, you'll just have to go into the Terminal and invoke the script and then refresh the SWF. I set up my site as such:
  • /flash - this is where my Flash SWF file would be, as well as the HTML template to load it in.
  • /index.html - just loads the CGI script.
  • /cgi-bin - location of CGI and variable file.
  • /files - the location of my PDF directories, sorted in directories named for the variables they would load as.
  • /vars - location of some text files it would just load into variables that the name of file signified.
Now, how do you get Flash to update its files every time someone clicks on your site? Simple; have index.html use a frame to send you to the CGI file, and the base.html is the file with your Flash embeded, or in a frame (however you want Flash to be displayed). For instance:
<frameset cols="500" border="0">
<frame src="cgi-bin/loadvars.cgi">
[robg adds: I haven't, nor am I likely to, test this one, given my lack of knowledge of both Flash and Perl.]
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)

Use a Perl script to automate Flash content | 3 comments | Create New Account
Click here to return to the 'Use a Perl script to automate Flash content' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Do you know about Laszlo?
Authored by: ptwithy on Apr 15, '05 10:57:49AM

It uses the Flash player as runtime (because of its ubiquity), but I think it is _much_ simpler to program in. Just use any old text editor. It has the ability to fetch an xml file from a server or use SOAP for data feeds. It's open source, and free (unless you want to hire them to do your app for you or train you, etc.).

If you are in to eclipse, IBM have a plug in for developing Laszlo under eclipse:

[ Reply to This | # ]
Use a Perl script to automate Flash content
Authored by: Fred E. Webber on Apr 16, '05 10:08:12PM
I'm not certain about OpenLaszlo, though it sounds intriguing. But I'm a hacker at heart and prefer simple tasks to be handled simply. The PERL code presented in this article was a bit buggy and verbose ; so here's a cleaner example:

#! /usr/bin/Perl
$| = 1; # flush buffer

$webServerRoot = "/Library/WebServer/Documents/";

use File::Find;
use CGI qw(:standard);

print STDOUT header(); # from CGI

find(\&findFilter, $webServerRoot);

sub findFilter {
  my ($theFileName) = $_;
  my ($pathAndFile) = $File::Find::name;
  my ($relPath) = $pathAndFile;
  $relPath =~ s/$webServerRoot//i;

  return unless ($theFileName =~ /\.html?$/i);
  print STDOUT "<a href=\"$relPath\">$theFileName</a><br>\n";
# or whatever you need it to look like

This could be much simpler: basically a one-liner grep, but I already had this handy. Also, if you call the cgi directly from Flash via:

"loadVariablesNum ("dirgrep.cgi", 0);"
you don't need to go through the intermediary step of writing to a file (which may cause file lock issues.)

[ Reply to This | # ]
Use a Perl script to automate Flash content
Authored by: bloodycelt on Apr 18, '05 05:47:37AM

I am sorry to say that while I found the criticism of the buggy and verbose script, your script does not work at all.

1. LoadVariablesNum refuses to load scripts for me, it gives errors and only loads variables from text files. I use Flash MX 2004. Thats what it does.

2. Even so the output must be formatted as var=value&var2=value2 format.

3. My goal was to have separate variables for each directory since I was using the directory structure to organize my files. Your script would just list all of them in one huge listing.

I am working on cleaning the script up and ill repost it hopefully in a more readable manner.

[ Reply to This | # ]