Thanks for the help. I've extended your example a bit and I'm on my way to 
making Lemmings in HaXe, except I've run into a bit of a snag where flash9 
differs from what I'm used to.

Before I was using something like follows to make the mainloop of my programs:

private var _container : MovieClip;
...
 _container = flash.Lib._root.createEmptyMovieClip ("Container", 1);
_container.onEnterFrame = mainLoop;
...
private function mainLoop () : Void
{
  Tick += 1;
....
}

Apparently not only has MovieClip moved into display in flash9 but it no longer 
has a onEnterFrame method.  So, I don't know how to do something similar in 
flash9.  I'm assuming the nextFrame function in MovieClip is essentially the 
same as the onEnterFrame was before, but I'm not sure how to use it.  When I 
try flash.Lib.current.nextFrame = mainLoop; I get an error "Main.hx:37: 
characters 8-35 : Cannot redefine method with Flash9 : please use 'f9dynamic' 
before method declaration"



import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.Shape;
import flash.geom.Rectangle;

class Main
{
    static var instance : Main;
    static var img      : Image;
    static var Tick     : Int;

    public static function main () : Void
    {
        instance = new Main();
    }

    function new ()
    {
        img = new Image( 640, 480 );
        flash.Lib.current.addChild( img );
        img.drawRectangle( 0, 0, 100, 100, 0xff0033cc );
        img.drawRectangle( 20, 20, 60, 60, 0xff006400 );

        //img.data.fillRect(new Rectangle(0, 0, 20, 20), 0xffffffff);
        img.drawCircle(200, 200, 50, 0xff0033cc, 0xff000000, 10);
        img.drawRect(0, 0, 20, 20, 0xffffffff, 0xff000000, 1);
        img.drawRoundRect(0, 0, 200, 200, 50, 0xffffffff, 0xff000000, 1);
        img.drawCircle(500, 300, 50, 0xff0033cc, 0xff000000, 10);
        img.drawLine(0,0, 100, 100, 0xff000000, 20);
        img.drawCurve(50,50, 100, 100, 0xff000000, 20);
        img.drawEllipse(200, 200, 20, 100, 0xff0033cc, 0xff000000, 10);
    }
}

class Image extends Bitmap
{
    public var data  : BitmapData;
    public var shape : Shape;

    public function new ( width : Int, height : Int )
    {
        data = new BitmapData( width, height );
        shape = new Shape();
        super( data );
    }

    public function drawRectangle( x : Int, y : Int, width : Int, height: Int, 
ARGBcolor : UInt ) : Void
    {
        for( py in 0...width )
        {
            for( px in 0...height )
            {
                data.setPixel32( x + px, y + py, ARGBcolor );
            }
        }
    }

    public function drawCircle( x : Int, y : Int, r: Int, fillColor: UInt, 
lineColor: UInt, lineWidth: UInt )
    {
        shape.graphics.beginFill(fillColor);
        shape.graphics.lineStyle(lineWidth, lineColor);
        shape.graphics.drawCircle(x, y, r);
        shape.graphics.endFill();
        data.draw(shape);
    }

    public function drawEllipse( x : Int, y : Int, w: Int, h: Int, fillColor: 
UInt, lineColor: UInt, lineWidth: UInt )
    {
        shape.graphics.beginFill(fillColor);
        shape.graphics.lineStyle(lineWidth, lineColor);
        shape.graphics.drawEllipse(x, y, w, h);
        shape.graphics.endFill();
        data.draw(shape);
    }

    public function drawRect( x : Int, y : Int, x2 : Int, y2 : Int, fillColor: 
UInt, lineColor: UInt, lineWidth: UInt )
    {
        shape.graphics.beginFill(fillColor);
        shape.graphics.lineStyle(lineWidth, lineColor);
        data.fillRect(new Rectangle(x, y, x2, y2), fillColor);
        shape.graphics.drawRect(x, y, x2, y2);
        shape.graphics.endFill();
        data.draw(shape);
    }

    public function drawRoundRect( x : Int, y : Int, x2 : Int, y2 : Int, r: 
Int, fillColor: UInt, lineColor: UInt, lineWidth: UInt )
    {
        shape.graphics.beginFill(fillColor);
        shape.graphics.lineStyle(lineWidth, lineColor);
        shape.graphics.drawRoundRect(x, y, x2, y2, r);
        shape.graphics.endFill();
        data.draw(shape);
    }

    public function drawLine( x : Int, y : Int, x2 : Int, y2 : Int, lineColor: 
UInt, lineWidth: UInt )
    {
        shape.graphics.lineStyle(lineWidth, lineColor);
        shape.graphics.moveTo(x, y);
        shape.graphics.lineTo(x2, y2);
        data.draw(shape);
    }

    public function drawCurve( x : Int, y : Int, x2 : Int, y2 : Int, lineColor: 
UInt, lineWidth: UInt )
    {
        shape.graphics.lineStyle(lineWidth, lineColor);
        shape.graphics.moveTo(x, y);
        shape.graphics.curveTo(x, y, x2, y2);
        data.draw(shape);
    }
}
------------------------------
       
---------------------------------
Choose the right car based on your needs.  Check out Yahoo! Autos new Car 
Finder tool.
_______________________________________________
osflash mailing list
[email protected]
http://osflash.org/mailman/listinfo/osflash_osflash.org

Reply via email to