Haxe Forum > How I made an image in flash

  • Hi all,

    I would like to ask the hexe experts here to have a look at what I did and tell me is it correct what I do (or am i just lucky that it works?)

    This is my hexe code:

    class Tutorial
    {
        static function main()
        {
            var s = new Smiley();
            flash.Lib.current.addChild(s);
        }
    }

    and this is my compiler script:

    -main Tutorial
    -swf-version 11
    -swf-header 800:600:30
    -swf-lib resource.swf
    -swf test.swf

    So no class declaration in the hexe code.
    The class "Smiley" is defined in the resource.swf file I made online with http://code.google.com/p/hxswfml/ (I used a Smiley.png file).
    If I define the class "Smiley" in the hexe code I get the error that the class is already defined in the resource.swf file.
    If I use @:bind to "redefine" the class I get no output.
    Just removing the class definition did the trick and I got my :)

  • Oh sorry: hexe > haxe (this is my second day of using haxe lol). May i suggest an edit-you-own-text button in the forum?

  • Your code is correct. The class Smiley is created by hxswfml and is inside resource.swf.
    By using -swf-lib the haxe compiler will extract all classes from the resource.swf and compile them into your test.swf.

    If you want to write your own class you have to use @:bind as you already found out. An example for that would be:

    import flash.Lib;
    import flash.display.Bitmap;
    import flash.display.Sprite;
    @:bind class Smiley extends Bitmap
    {
        public function new()
        {
            super();
            trace("I smile");
        }
    }
    class Main extends Sprite
    {
        public function new()
        {
            super();
            var bitmap = new Smiley();// will show 'I smile' as debug statement in the test.swf
            bitmap.x = 200;
            addChild(bitmap);
        }
        static function main()
        {
            Lib.current.stage.addChild(new Main());
        }
    }

    You may have already discovered but the online example of hxswfml shows how to use it in haxe:
    1) click the icon next to the file name : http://www.haxer.be/hxswfml_examples/hxswfml-online-tut1.jpg
    2) click the silver bar in the popup : http://www.haxer.be/hxswfml_examples/hxswfml-online-tut2.jpg
    3) look at the source code and/or press the zip-button : http://www.haxer.be/hxswfml_examples/hxswfml-online-tut3.jpg

    Cheers,

    Jan

  • Thank you for verifying my code and confirm that it is correct haxe.

    Indeed I had discovered the piece of code in hxswfml, but I did not realise that I had to use this code in my program.
    At that time I was following this tutorial: http://blog.neurotoxic.org/post/2009/01/13/first and got to the point where you have to make a resource file using swfmill. I tried to install swfmill but could not get it up and running because of missing or incompatible dll files. So I looked for alternative ways to make a resource.swf file. I found hxswfml which seemed to work great, but still no smiley image showed up in the flash screen. Then I found this page: http://haxe.org/com/swfmill and things became fuzzy to me :). I can't remember where I read about binding using class instead of binding using strings but suddenly a smiley showed up without even defining any class...

    I know I should improve my IDE, so far I only used notepad so i am practically blinded as to what I am doing. Your demo how to use the trace command is valuable: I need to figure out how to get the compiler talk to me, how to keep track of the content of variables and of program flow and other debugging techniques (any suggestions are welcome). But it's fun when things suddenly appear to work :)

< Prev | Page 1 / 1 | Next >