views:

29

answers:

2

Okay so I have two import pieces of code involved in this. This first tiny bit is what creates an object called OBJECT_arrow. It is located in the main function of my main class:

new OBJECT_arrow().CREATE(this,200,200);

It isn't really all that important. Now this next bit is the OBJECT_arrow class. What it does is loads an external png image and draws it.

package
{
    import flash.net.URLRequest;
    import flash.display.*;
    import flash.system.*;
    import flash.events.*;
    import Math;
    public class OBJECT_arrow extends Sprite
    {
        public var X:Number = 0;    public var Y:Number = 0;
        public var DEPTH:int = 0 ;
        public var CONTAINER:Sprite = new Sprite();
        public var imageLoader:Loader = new Loader();
        public var image:URLRequest = new URLRequest ('ARROW.png');
        public function CREATE(CONTAINER:Sprite,X:Number,Y:Number):void
        {
            this.X = X;     imageLoader.x = this.X;
            this.Y = Y;     imageLoader.y = this.Y;
            this.CONTAINER = CONTAINER;
            CONTAINER.stage.addEventListener(Event.ENTER_FRAME,STEP);
            imageLoader.load(image);
            DRAW();
        }

        public function STEP(event:Event):void
        {
            DRAW();
        }

        public function DRAW():void 
        {
            addChild (imageLoader);
            (CONTAINER as MAIN).DRAW_LIST[(CONTAINER as MAIN).DRAW_LIST.length] = this;
            (CONTAINER as MAIN).DRAW_LIST[(CONTAINER as MAIN).DRAW_LIST.length] = DEPTH;
        }
    }
}

Now I know the mathematics behind rotation and know to rotate before I translate and everything but I simply don't know how to apply the transformation to an external image in as3.

+1  A: 

When you load an image with Loader it is stored as an object of type DisplayObject.

If you want it to be rotated, just set the rotation property.

Gunslinger47
+1  A: 

To apply a matrix, you can use the transform() method of the DisplayObject.

You should also take a look at the BitmapData (raw image data) and Bitmap (DisplayObject to hold the BitmapData) classes. Depending on the complexity of what you're trying to do, they may serve you better. Specifically, BitmapData will allow you to lock() the image while you are fiddling with its bits. Flash won't render the BitmapData until you unlock() it, which can be a great performance improvement if you're doing a lot of fiddling.

DJH
+1 for literally answering 1101's question, though it may be a little too technical for a beginner.
Gunslinger47