-
[AS3] slideshow problem
I am coding a simple slideshow, where I load images with XML, and then tween through them.
The tween/transition is basically a function I wrote to cut the image in small pieces and have each individual piece tween in. This works well enough for jpg/png, but as soon as I try doing this with a swf instead of a image, strange lines appear, as if it didn't load the entire swf, or couldn't extract the bitmapdata.
Code:
private function chopImage(cimg:Loader,holder:Sprite):void
{
var mainPic:BitmapData = new BitmapData(cimg.width, cimg.height, false);
mainPic.draw(cimg,null,null,null,new Rectangle(0, 0, cimg.width, cimg.height));
for (var i:int = 0; i < splitv; i++)
{
for (var j:int = 0; j < splith; j++)
{
var bmd:BitmapData = new BitmapData(cimg.width / splith, cimg.height / splitv);
bmd.copyPixels(mainPic,new Rectangle(j * (cimg.width / splith),i * (cimg.height / splitv),cimg.width / splith, cimg.height / splitv),new Point(0,0));
var bm:Bitmap = new Bitmap(bmd);
var temp:Sprite = new Sprite();
temp.addChild(bm);
slide.addChild(temp);
temp.x = j * (cimg.width / splith);
temp.y = i * (cimg.height / splitv);
);
}
}
slide.x = (stage.stageWidth - slide.width) / 2;
slide.y = (stage.stageHeight - slide.height) / 2;
Any suggestions?
-
maybe try setting the container clip's cacheAsBitmap property to true. If you are confident that the swf is completely loaded when you are trying to create your bitmapdata copy.
-
that didn't work. any other suggestions?
-
can you post a screenshot of these strange lines ? What is in this swf you are loading ? do you have smoothing turned on ? have you tried it with multiple swfs , or just with one ? What steps if any , besides bitmap caching have you taken to try to debug this problem ? Is this swf fully loaded , ie , are you waiting for the Event.COMPLETE event before preforming this bitmap capture on the container sprite or loader ?
-
http://img218.imageshack.us/img218/2328/swfproblem.png
That swf is just a jpg image turned to swf....no animation, no code.
I have tried with several swfs, and for each the lines appear differently.....so I am guessing I am missing something in my code. The display function is called from Event.COMPLETE, so I don't think that is the problem either....
I don't have any idea how else I can debug this problem!
-
add this argument , 0xFFFF00 , to your bitmap data constructor , so :
Code:
BitmapData(cimg.width / splith, cimg.height / splitv , 0xFFFF00 )
if those lines turn yellow , then we know the problem is with your either your syntax and or logic, specifically because the lines are actually the fill color , meaning you are either positioning your pieces incorrectly , or the rectangle used to define the bitmap region is off. copyPixels is not to be used on anything that has been scaled , stretched , etc, so if there is anyway that somehow your loaded swf is being sized , that value will be off. I would also check to make sure the width of your pieces adds up to the width of the loaded swf. Also if you havent already , add mainPic to the display list , so you can see it. If it too shows those lines then we can at least identify that the problem is happening before you cut it up into new pieces.
-
nope mainPic seems just fine, the problem is, i think, with the clipRect property.
-
i honestly don't really see the need for mainPic at all , or why you are using copyPixels in this case. If i were you i would ditch that , and in your loop just use the draw method and the original display object as the source. And really you could simplify this whole thing by creating a sprite , with X number of sprites with rectangular fill's as children , set it as a mask, and move , tween its children. There's no need to do all these bitmap data conversions , its far more processor intensive then its needs to be.