Making links in a flash-banner, without source

    What for?



    Have you ever received a layout with flash elements that should be links to external or internal resources, but in fact they are not? At the same time, when you are not a flash developer and the Flash IDE is not at hand (or even the operating system you are working in does not support this Flash IDE) - this becomes a little embarrassment. You can, of course, kick the layout designer so that he corrects everything, but it takes time, and therefore money. Also, kicking it every time the URL changes is not a good idea.

    Swftools come to the rescue



    On the developer's site you can find out that this is a set of console utilities for working with .swf files. These utilities are good and different (for example, the ActionScript compiler does not know how to compile Box2D, that is, not all ActionScript syntax understands), but they will cope with our task.
    Utilities, by the way, can:
    • convert to swf from pdf (PDF2SWF)
    • pull content from swf movies (SWFDump, SWFStrings, SWFBBox, SWFExtract)
    • convert some graphic / audio / video file formats to swf (JPEG2SWF, PNG2SWF, GIF2SWF, WAV2SWF, AVI2SWF)
    • import TTF, Type1 (Font2SWF) fonts into a swf movie
    • compile ActionScript3 code with certain limitations


    Good, but links in banners how to make?



    Here, another console program from the swftools suite called swfc will help us. It allows you to collect flash movies based on the description of their special markup language.

    Suppose we have a banner with a size of 980 by 136 pixels in the banner.swf file and we want that when it is displayed in the browser on our site, it should refer to the main page of the habr.
    Create a movie.sc text file with the following markup:

    # file name with video, its size and playback speed
    .flash filename = "banner_with_link.swf" bbox = 980x136 fps = 12
    # our banner
    .swf banner "banner.swf"
    .put banner
    # a transparent rectangle over it
    .box rect width = 980 height = 136 color = red fill = # FFFFFF00 line = 0
    # assemble the rectangle into the "button" entity
    .button mybutton
        .show rect as = shape
        # by clicking on the button, the specified link goes
        .on_press:
            getURL ('http://habrahabr.ru/', '_top');
        .end
    .end
    .put mybutton
    .end
    


    It remains to collect the swf movie from this file using the swfc utility:
    swfc movie.sc
    As a result of the assembly, we get the banner_with_link.swf file with the functionality we need in the same directory.

    So what?



    Actually, the task has been completed, but you can not stop there. After all, the assembly does not have to take place on your machine - just install this utility on the server and the banners can be collected dynamically. With proper caching, this has almost no effect on performance. In the References section on the developer's site, there are examples of projects working on this technology. And after studying the materials of the wiki documentation and open source codes of the project, you will have many other great ideas for using it. Dare, and do not forget to write about it on the hub!

    Also popular now: