Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Just another Perl shrine
 
PerlMonks  

Outputting Text To Flash

by mt2k (Hermit)
on May 27, 2002 at 22:44 UTC ( #169659=perlquestion: print w/ replies, xml ) Need Help??
mt2k has asked for the wisdom of the Perl Monks concerning the following question:

I have recently installed Flash 5 on my computer. Working with it is a fun challenge (Though I wish I could at least draw stick people!). Now, how is this relevant to perl?

Well, as anyone who has seriously used Flash before knows about the loadVariables() and/or loadVariablesNum() functions. These functions allow you to load text/variables and save them back from an external file. Now, one can use simple text files but bleh! For dynamic data, you have to use some language! Now, I have seen all the articles about using PHP or ASP to do so, etc. etc. but of course I thought about perl! ;)

Here is the one-liner that would load in variables for me:

loadVariablesNum ("script.pl", 0);

The input received by the flash file from the script must be formatted as follows:

name1=value1&name2=value2&name3=value3 and so on. This is the same format that is used for query strings attached to URLs. So I have one question... What module should I be looking at to escape characters like the following:

Character '&' to '%26'
Character '+' to '%2B'
Character '<' to '%C3'
etc, etc, etc.

Is this the job for HTML::Entities, URI::Escape or something else? Encoding these special characters is the only way to pass them to flash, so it needs to be done. Thanks a bunch!

P.S.: Now to go off and do the thing I should have done first: making sure that the script is exectued when called by flash, and not just the script code being read in ;)

Comment on Outputting Text To Flash
Select or Download Code
Re: Outputting Text To Flash
by mt2k (Hermit) on May 27, 2002 at 23:21 UTC
    Yep, I should have known that this was a simple problem to solve... Don't ask me why, but I did not try the most obvious flicking thing on the planet: reading the perldocs for HTML::Entities and URI::Escape. Of course, I even had the answer in my post (just a little hidden):

    "This is the same format that is used for query strings attached to URLs"

    Now, since you are saying "but you should use URI::Escape, of course!" then you are right ;)

    So a perl script to do a little work with flash:

    #!c:/perl/bin/perl -w use strict; # I am getting into the habit of using this! use URI::Escape; # For escaping special characters # Keys of this hash correspond to flash variable names: my %output = ( 'infobox' => '1+1=2 & 2+2=4 yep!' ); # Send the HTTP header (content-type does not seem to matter) # I have used text/plain since that sounds the best ;) print qq|Content-type: text/plain\n\n|; # Loop through each of the variables in the %output hash # Function - Encode characters and print them to flash for (my ($name,$value) = each %output) { print qq|$name=| . uri_escape($value) . "&"; }

    How to execute this from flash (the '0' as the second argument means to load the variables in global scope):

    loadVariablesNum ("path/to/script.pl", 0);

      A very elegant solution no doubt (may be could have used CGI.pm ;).

      Also FlashMX requires (by documentation and experience) that the content type be application/x-www-urlform-encoded. Although it has no problem getting static text files back as text/plain, I think it requires the specialized type when it has tried sending variables through. You never know which of your users have upgraded to the "Flash 6" browser plugin, so you might want to be careful.

      -- termix

Re: Outputting Text To Flash
by jmcnamara (Monsignor) on May 28, 2002 at 07:24 UTC

    It isn't quite the way that you intended but it may suit your needs. The Perl::Flash module uses the libswf.a library to directly create and manipulate Flash movies. It doesn't seem to be on CPAN so you will have to download it from that site.

    On a similar theme there is also the SWF::File module.

    --
    John.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://169659]
Approved by rob_au
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2014-04-20 20:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (487 votes), past polls