PDA

View Full Version : creating bitmapdata objects in a loop won't work!


darth
03-26-2008, 11:36 AM
Hi I have this function in the main/document class that I need to create slices of a Sprite containing graphics -


public function slices(event:Event):void{
var effect:Sprite = new Sprite()
addChild(effect)
effect.y = 115
for(var i:uint = 0; i<8; i++){
var bitmapdata:BitmapData = new BitmapData(1280, 100, true, 0x00FFFFFF)
var bitmap:Bitmap = new Bitmap(bitmapdata)
var mc:Sprite = new Sprite()
effect.addChild(mc)
mc.y = i*100
mc.addChild(bitmap)
var rect:Rectangle = new Rectangle(0, i*100, 1280, 100)
bitmapdata.draw(content, null, null, null, rect)
}
}

Only the first slice is created and I can see it where it's supposed to be but after that theres nothing?
What am I doing wrong?

amarghosh
03-26-2008, 01:12 PM
i tried it after changing the alpha in bitmapdata constructor and it seems it is drawing on top of one another

var bitmapdata:BitmapData = new BitmapData(1280, 100, true, 0xFFFF0000);

darth
03-26-2008, 01:20 PM
Yes exactly. I was supposing that when I use the rectangle it will take the area and draw it from x0, y0 in the bitmap but it places it exactly in the same place in the bitmap... So now I need to figure out how to take only the 100px height area and put it into a 100px height bitmap x0 and y0...

darth
03-26-2008, 01:31 PM
public function slices(event:Event):void{
var effect:Sprite = new Sprite()
addChild(effect)
effect.y = 115
for(var i:uint = 0; i<8; i++){
var bitmapdata:BitmapData = new BitmapData(1280, 800, true, 0x00FFFFFF)
var bitmap:Bitmap = new Bitmap(bitmapdata)
var mc:Sprite = new Sprite()
effect.addChild(mc)
mc.addChild(bitmap)
var rect:Rectangle = new Rectangle(0, i*100, 1280, 100)
bitmapdata.draw(content, null, null, null, rect)
}
}

This will make it show but as you can see the source will be copied to the same x and y coordinates.