package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.net.URLVariables;
import flash.net.URLRequest;
import flash.events.Event;
public class Init extends Sprite {
var rects:Array,
numRects:int = stage.stageWidth / _width + 1,
_width:Number = 20,
_height:Number = 80,
_rotation:int = 0;
public function Init() {
init();
}
function init():void
{
rects = new Array();
for(var i:int = 0; i < numRects; i++)
{
var rect:Rect = new Rect();
rect.x = i * 20;
addChild(rect);
rects.push(rect);
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
function onEnterFrame(e:Event):void
{
for(var i:int = 0; i < numRects; i++)
{
rects[i].rotationY += 1;
}
_rotation += 1;
if(_rotation % 180 == 0)
{
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
}
}
}
And this is the Rect class:
package {
import flash.display.Sprite;
public class Rect extends Sprite {
private var color:uint,
_width:Number,
_height:Number;
public function Rect(color:uint = 0x000000, width:Number = 20, height:Number = 80) {
this.color = color;
this._width = width;
this._height = height;
init();
}
function init():void
{
graphics.beginFill(color);
graphics.drawRect(0, 0, _width, _height);
graphics.endFill();
}
}
}
So I create many rectangles and move them each loop by 20 pixel, so by now they are filled with color, but what if I have a large image by height equal to these rectangles, and cut that image and fill each of these rectangles with the part of the image, just as making puzzle parts, I’ve imported the images to my library, but now i don’t know how to do it please any ideas?
In short: If you are splitting an image, use Bitmaps as your Rect children or base, and use underlying
BitmapData.copyPixels()method to fill your rects’ bitmaps with pixels from one big image. An example:This splits one huge
megabaseimage into several 64×64 images arranged as a Vector of BitmapData objects. You will obviously have a different underlying structure, but the main principle is illustrated here.