AS3 fullsize background image with pixel pattern
in Code, Flash, Free Stuff | 6 commentsI have written a small class, which you may be interested. With this class you can create a fullsize background image which fits to the width of the stage. The height of the image is proportional to the width. So it´s good to use an image with a ratio of 4:3 otherwise empty bars can show up.[loadprettifier]
To round it up I create a pixel pattern overlay so the image quality is acceptable by streching it. Known from other sites…
So thats the way to do it:
// import the class
import com.fullsizeBackgroundImage.fullsizeBackgroundImage;
// create a new object, give the url to the image as string
var backgroundImage:fullsizeBackgroundImage = new fullsizeBackgroundImage("images/background.jpg");
// add the object to stage
stage.addChild(backgroundImage);
If you have any question about the script feel free to leave a comment
Comments
Leave a Reply
Please fill all the fields with the red star *
«Tom» said on :
Hi, I’ve used your code to add the image and more importantly the pattern overlay, but it appears on top of everything (I have somethings on layers within my flash file). I’ve tried using addChildAt and setChildIndex to move it to the back but with no result. I’ve also tried assigning the child to an empty movieclip which is ordered to the bottom instead of the stage (emptyMc.addChild(backgroundImage); and that has no effect either….any thoughts? Thanks.
«solemone» said on :
Hi Tom,
there is a bug in the code that I don´t find. But I´m planning a new class. Until then you can check out this Quick Tip from ActiveTuts+:
Quick Tip: How to Automatically Resize an Image to Fit the Screen
Or this AutoFitArea class from Greensock.com
«Michel» said on :
Hi, great code but how can we add more space between pixel
Thx
«solemone» said on :
Hi Michel,
you can change line #65 in the class:
from this: patternBitmapData = new BitmapData(2, 2, true, 0×000000);
maybe to this: patternBitmapData = new BitmapData(4, 4, true, 0×000000);
To change your width of the bitmap data, which is the repetitive element and not the individual pixels.
«Michel» said on :
HI solemone,
it works, really cool but it was easy to figure it out, so newbie i am lol ( i’ll go buy a new brain)
have a nice day
thx a lot
«Cesar» said on :
OMG! Thanks so much! I stay looking for this for a months ago!
Have a nice day, thanks a lot!!
From Brazil