flash snippets

Create an flv movie

Tagged flv, movie, audio, ffmpeg, flash  Languages bash

Create an flv movie that is 320 wide by 240 high. For audio functionality ffmpeg needs to be compiled with the following parameters:


The snippet itself:

ffmpeg -i mymovie.avi -s 320x240 -ar 44100 -r 12 mymovie.flv

Add duration metadata into flv movie

Tagged flv, movie, flash, duration, metadata, flvtool2  Languages bash

By default an flv movie doesn't contain the duration metadata. Using the flvtool2 program it is injected like this into the movie file.

cat mymovie.flv | flvtool2 -U stdin mymovie.flv

How to display Flash messages in Rails

Tagged flash, rails, erb, haml  Languages ruby

Place the following in your ERB view:

<% [:info, :error].each do |key| %>
  <% if flash[key] %>
  <div class="<%= key %>" id="flash">
    <%= flash[key] %>
  <% end %>
<% end %>

or use the following if you prefer Haml:

- [:notice, :error, :success].each do |key|
  - unless flash[key].blank?
    %p{ :class => "flash #{key}" }= flash[key]

How to implement copy-to-clipboard functionality that works with Flash 10

Tagged copy, clipboard, copy-to-clipboard, clippy, flash 10, flash  Languages 

Use mojombo's Clippy which can be downloaded from GitHub.

How to create a custom button

  • First create your button and save it as a PNG file.
  • Change library.xml to use your button.
  • Customize the code behind the button by modifying clippy.hx. You can, for example, remove the "Copy to clipboard" label.
  • Set the width and height of the button. You have to set it in almost all files (compile.hxml, library.xml, etc).
  • Compile the SWF file:
swfmill simple library.xml library.swf && haxe compile.hxml


There are no good alternatives that I know of. I tried ZeroClipboard and other solutions, but they were full of bugs and not customizable.

How to Implement Flash for Sinatra with Cookies

Tagged flash, sinatra, ruby, rails, cookie, rack-flash  Languages javascript, ruby, css

Storing your application’s flash messages in a cookie means you can cache the whole page.


def flash(key, value)
  fail "Invalid key '#{key}'" unless [ :info, :error ].include?(key)
  response.set_cookie "flash_#{key}", value: I18n.t(value), path: '/'

Put the code in a helper or controller.


var Flash;

Flash = (function() {
  function Flash(flash_holder, cookie_prefix) {
    this.flash_holder = flash_holder;
    this.cookie_prefix = cookie_prefix;
    if (this.flash_holder == null) {
      this.flash_holder = '#flash';
    if (this.cookie_prefix == null) {
      this.cookie_prefix = 'flash_';

  Flash.prototype.show = function() {
    var i, key, len, name, ref, results, value;
    ref = ['info', 'error'];
    results = [];
    for (i = 0, len = ref.length; i < len; i++) {
      key = ref[i];
      name = this.cookie_prefix + key;
      value = Cookies.get(name);
      if (value) {
        $(this.flash_holder).attr('class', name).html(value).show('fast');
      } else {
        results.push(void 0);
    return results;

  return Flash;


$(function() {
  new Flash().show();
  return new Flash('#flash_holder', 'cookie_prefix').show();


<div id="#flash"></div>


#flash {
  display: none

.flash_info {
  color: darkgreen

.flash_error {
  color: darkred


In your controller:

get '/' do
  flash :info, 'login.failed'