forum > Problem using Swfmill and HaXe

  • I want to display a movieclip.I use Swfmill 3.0.2.I made a file called resource.xml:

    <?xml version="1.0" ?>
    <movie version="9">
        <frame>
            <library>
                <clip id="men" import="men.png"/>
        </library>
        </frame>
    </movie>

    I put it and men.png into folder swfmill.
    And call:swfmill simple resource.xml resource.swf.
    my code in HaXe:
    class Tutorial
    {
        static function main()
        {
            var s:flash.display.MovieClip = flash.Lib.attach("men"); // "men" is the name defined in the resource.xml file
            flash.Lib.current.addChild(s);
        }
    }

    Compile.hxml:
    -main Tutorial
    -swf-version 9
    -swf-header 320:240:30
    -swf-lib resource.swf
    -swf tutorial.swf

    I call:HaXe compile.hxml.My swf is empty.I've tried all versions of swfmill.It gives me the same results.
    Folder haXe contains men.png, resource.swf, Tutorial.hx, compile.hxml.

  • Contrary to AS2/AVM1/flash8 swf's where a string is used as linkage, AS3/AVM2/Flash9 swf's need a class linked to the symbol.
    Swfmill cannot create this class (only the old string linkage).
    In the past (before haxe 2.06) the haxe compiler would create these classes automatically, but since 2.06 it no longer does. See the CHANGES.txt file in your installation directory:

    no longer support automatic creation of classes for f8 swfs in f9 mode

    The solution is to create this class yourself in your haxe file with the same name as the linkage in swfmill.
    Since classes in haxe must start with upper case, you have to change id 'men' to 'Men':
    <?xml version="1.0" ?>
    <movie version="9">
        <frame>
            <library>
                <clip id="Men" import="men.png"/>
        </library>
        </frame>
    </movie>

    Then add an 'empty' class 'Men' to your hx file and simply instantiate it just like any other class with 'new' (instead of attach)

    class Men extends flash.display.MovieClip{}
    
    class Tutorial
    {
        static function main()
        {
            var s = new Men();
            flash.Lib.current.addChild(s);
        }
    }

    Jan

  • I works.It worked.So,how do I compile with Flash v8?

  • how do I compile with Flash v8?
    Do you mean how to use Flash Pro8 instead of swfmill?
    If so,
    * drag an image from a folder on your PC (or even straight from a webpage) to the stage/canvas in Flash pro8
    * convert your image to movieclip by selecting it and then do 'Convert to symbol' (or press F8),
    * go to the library and edit the properties of the movieclip symbol
    * add a linkage identifier (no class)
    * make sure 'export for actionscript' and 'export in first frame' are checked'
    * publish and then include it with -swf-lib.
    For example: AS2 linkage

    Jan

  • I mean I want to run swf in flash player 8(change -swf-version 9 to -swf-version 8)

  • Then your original example will work. Just change -swf-version 9 to 8

    Jan

  • Sorry,Why sometimes I get Class not found:flash.display.MovieClip{}, Tutorial?

  • flash.display.MovieClip is for -swf-version 9 and higher
    http://haxe.org/api/flash/display/movieclip

    flash.MovieClip is for -swf-version 8 and lower
    http://haxe.org/api/flash8/movieclip

    Jan

  • I have read the document.I do not see LoadVar in flash 9

  • You said you wanted flash8, so why look in flash9 then? :s
    It's LoadVars with an S at the end by the way.
    http://haxe.org/api/flash8/loadvars
    I also already gave you a complete working example for LoadVars. (yesterday) so I have no idea what you're intentions here are. :s

    Jan

  • Haxe allows you to target both of the virtual machines embeded in the flash player. Generally speaking for flash 8 and below, haxe targets AVM1 and for flash 9 and above haxe targets AVM2. Basically the bytecodes and design used in the two virtual machines are very different although they are similar in concept. Haxe also has a library called NME that allows you to remap AVM2 ( flash9+ ){ flash code to run on Neko virtual machine or c++ and therefore run natively on many phones and desktops and there is some support for javascript target via jeash.

    So for flexibility it is very hard to justify coding haxe for flash8 since flash9+ haxe is much more suitable to be modified and run also outside flashplayer. If we look at the commercial market for flash content, we see that currently all new flash content is created using as3 or tools that create AVM2 bytecode ( haxe for flash9+ ). There is one exception, many flash banners are still created for flash8, this is because they are often hacked together by old school flash designers and using lots of timeline and do not need all the features of more recent players but do care very heavily about user base. So unless you are intending to develop banners and even so I would not advise targetting flash8 player.

    For some more details about avm1 and avm2 maybe check out something about communicating between so you realise they are very difference:
    http://www.kirupa.com/forum/showthread.php?223798-ActionScript-3-Tip-of-the-Day/page17&p=1964550#post1964550

    ( such approaches could be easily converted to pure haxe code incidentally ).

    So getting back to the topic.... if you want to learn about communicating between backend and frontend with haxe I suggest you read the haxe remoting tutorials, yes you can approach it in the ways that Jan has explained when answering your question at face value, but I think it would be better to explore haxe remoting which is why I posted at a tangent. It would be interesting to see a AVM1 to AVM2 haxeremoting example, I am not sure anyone has bothered to do this but I am sure it could work very well.

  • yes, I've read flash 8.I just do not understand why flash 9 no LoadVar.
    Now,I can move a movieclip.So,How do I attach second movieclip to first movieclip as mc_first-----mc_second?

  • flash9 haxe does not have LoadVars because it targets a different set of bytecodes to flash8 haxe, for instance see as2 and as3 example.
    http://blog.csdn.net/meqxx/article/details/5603322
    Haxe for flash9 will be almost the same as the as3 example.
    This link may help with your other question.
    http://haxe.org/api/flash/display/movieclip

  • just do not understand why flash 9 no LoadVar.

    flash 9/AS3 does have a 'LoadVars equivalent', it's called URLLoader / URLVariables.
    http://haxe.org/api/flash/net/urlloader
    http://haxe.org/api/flash/net/urlvariables
    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html

    You can also google this:
    https://www.google.com/search?q=LoadVars+in+AS3

  • I will read them.Thanks Jan and Justin.Now,I know how to run the swf on the server and the difference between flash 8 and flash 9.

< Prev | Page 1 / 1 | Next >