[mtasc] thoughts about 32K bytecode limit

David Rorex drorex at gmail.com
Wed Jun 15 23:33:00 CEST 2005


(Thierry V. <titi2027 at netplus.ch>: Thanks, I figured it out already
from one of the examples. Your example is not quite what I wanted,
what I want to do, is parse the xml into AS code, then compile the AS
code into a swf.)

Here's an example of what I'm doing now:

test.xml:
<data><args a="1" b="2" /> <fun go="now"></data>
converts to test.as:
data = {args:{a:"1", b:"2"}, fun:{go:"now"}}
converts to test.swf (ideally using mtasc, but that is limited to
32kB, so i used ming)

The advantage is, a 150KB xml file takes me approx 0.9 to 1.2 seconds
to load & process (over local network). When converted to .swf, it
becomes 65KB and takes 0.1 seconds to load (and no processing time).

The problem with ming is, then I'm tied to the server. I know ming can
be used as a C/C++ library, but for some reason it wasn't working for
me (giving me output swfs of 8 bytes, just the swf header but nothing
else) when I compiled with MinGW. (worked fine on linux, but like I
said, I would like to make it self contained and not depend on a
server)


Ideally, there would be an option added to mtasc to compile .as files
and just insert them onto the frame 0 of _root (not as classes).

-David R


In case anybody's interested, here's the source I used with ming:

as2swf.cpp 
----------------
//Compile in the ming/src dir with: 
//g++ -o as2swf as2swf.cpp libming.a -lpng -lz -lungif -I .
//(note that there are some bugs in mingpp.h that need to be fixed)
// Usage: as2swf input.as output.swf
// For some reason it works on linux but not windows for me
#include "mingpp.h"

#include <stdio.h>
#include <stdlib.h>


int main(int argc, char *argv[])
{
        if(argc < 3)
        {
                printf("Usage: %s input.as output.swf\n\n", argv[0]);
                exit(1);
        }
        Ming_init();
        Ming_setWarnFunction((void (*)(const char*,...))printf);
        Ming_setErrorFunction((void (*)(const char*,...))printf);
        Ming_setScale(20.000);
        Ming_useSWFVersion(6);
        SWFMovie *movie = new SWFMovie();
        movie->setDimension(10.0, 10.0);
        movie->setBackground(0xff, 0xff, 0xff);
        movie->setRate(10);
        FILE *fp = fopen(argv[1], "r");
        char buf[1024*1024];
        char *cp = buf;
        int size = 0;
        int nr = 1;
        while(!feof(fp) && nr > 0)
        {
                nr = fread(cp, 1, 1024, fp);
                cp+=nr;
                size += nr;
        }
        buf[size] = '\0';
        fclose(fp);
        fp = fopen("a.as", "w");
        fwrite(buf, 1, strlen(buf), fp);
        fclose(fp);
        printf("%d bytes read.\n", size);
        SWFAction *action = new SWFAction(buf);
        movie->add(action);
        movie->save(argv[2], 0);
        delete action;
        delete movie;
        printf("wrote to %s.\n", argv[2]);
        exit(0);

        return 0;
}





as2swf.php
----------------

<?
// either use flash+loadvars to post AS code to this script in the arg 'action'
// or run from the commandline, and it will read in code.as
// either way, it will output temp.swf (make sure the current dir is writeable)
ming_setScale(20.00000000);
ming_useswfversion(6);
$movie = new SWFMovie();
$movie->setDimension(10,10);
$movie->setBackground(0xff, 0xff, 0xff );
$movie->setRate(10);

if(!isset($_POST['action']))
{
    $dat = "";
    $fp = fopen("code.as", "r");
    while(!feof($fp))
    {
        $dat .= fgets($fp, 10000);
    }
    fclose($fp);

    $strAction = $dat;
}
else
{
    $strAction = stripslashes($_POST['action']);
}

$movie->add(new SWFAction( $strAction));
$movie->save("temp.swf");

?>



More information about the mtasc mailing list