http://qs1969.pair.com?node_id=662639

reasonablekeith has asked for the wisdom of the Perl Monks concerning the following question:

Morning Monks

As above really, is there a way to print the gen'd swf object, rather than being forced to save it to a file? I can't see it in the docs.

I did have a look through SWF::File and SWF::BinStream, but got a bit lost to be honest. Any nudges in the right direction would be appreciated.

Rob

---
my name's not Keith, and I'm not reasonable.

Replies are listed 'Best First'.
Re: SWF::Builder, printing the swf file, rather than saving it
by moritz (Cardinal) on Jan 16, 2008 at 11:33 UTC
    I tried to look into the source code of the modules, but the inheritance hierarchy got me confused ;-)

    Did you try to provide \*STDOUT or simply *STDOUT instead of a filename to see if it just works, magically and by chance? ;-)

    Of course you can also write a wishlist bug report against the appropriate module, and hope for a friendly CPAN author.

      ++!

      it really is as simple as

      $movie->save(*STDOUT);
      I had no idea you could do that! I'm not even sure exactly what's going on there, some light reading for me this weekend then!

      Thanks, Rob

      ---
      my name's not Keith, and I'm not reasonable.
Re: SWF::Builder, printing the swf file, rather than saving it
by hipowls (Curate) on Jan 16, 2008 at 11:36 UTC

    SWF::BinStream::File allows writing to a file handle, so use IO::Scalar to create a file handle that writes to a string and then you can print the string.

    I've not tested this code but something along these lines may do what you want.

    use SWF::File; use IO::Scalar; my $swf_data = ''; my $swf_fh = IO::Scalar->new( \$swf_data ); my $swf = SWF::BinStream::Write->new($swf_fh); ... $swf->close(); close $swf_fh; print $swf_data;

Re: SWF::Builder, printing the swf file, rather than saving it
by olus (Curate) on Jan 16, 2008 at 10:58 UTC
    Sending an object directly into the browser implies sending the appropriate MIME headers so that the browser recognizes the type of information to display.
    For an swf the mime-type is application/x-shockwave-flash.

    update: Sorry, not what was asked
      Yep, I realise this (and you have inferred correctly that I intend to serve the built object as an http response), but that doesn't answer my question.

      I'll be able to print the header okay, it's the binary data which forms the built swf object that I can't see how to get hold of (other than saving it to disk with a temp name, reading it, printing the contents in the response and then deleting the file, ug!)

      ---
      my name's not Keith, and I'm not reasonable.