01-28-2011 12:09 AM
I am trying to scale9grid an image. I am using the following code.
[Embed(source="assets/images/frame.png", scaleGridTop="5", scaleGridBottom="10", scaleGridLeft="5", scaleGridRight="10")] var paneFrame:Class; var frame:Image; /* Add the border */ frame = new Image(); frame.setImage(new paneFrame); frame.height = 300; frame.width = 300; addChild(frame);
When I do this, I get an empty screen. The image in question measures 15x50 pixels.
To note when I just remove the scaling parameters from the embed code, the image displays (all pixelated of course)
[Embed(source="assets/images/frame.png")] var paneFrame:Class; var frame:Image; /* Add the border */ frame = new Image(); frame.setImage(new paneFrame); frame.height = 300; frame.width = 300; addChild(frame);
Has anyone used scale9grid on a image successfully?
Solved! Go to Solution.
01-28-2011 02:41 AM
hey EraserX,
try using the following code:
[Embed(source="assets/images/frame.png", scaleGridTop="5", scaleGridBottom="10", scaleGridLeft="5", scaleGridRight="10")] var paneFrame:Class; var myContainer:Sprite = new Sprite(); var frame:Sprite = new paneFrame(); myContainer.addChild(frame); frame.width = 300; frame.height = 300; var myBitmapData:BitmapData = new BitmapData(300,300); myBitmapData.draw(myContainer); addChild(new Bitmap(myBitmapData))
i've looked around an apparently you have to add your image to a sprite first and then draw that sprite out as the source. something to do with non-transformable sources. and i used the Bitmap class instead of the image. im not a fan of the QNX image class yet but im warming up to it ![]()
here is the link to a good deal of info related to scale9grid:
http://www.dreaminginflash.com/2007/12/03/9-slice-
hope that helps. good luck!
01-28-2011 02:47 AM
Thanks JRab! I don't have experience working with bitmaps, so your example is definitely going to help! Also there aren't any other posts (that I could find) on this forum on scale9grids with bitmaps/images so I"m sure lots of other people will find it helpful too.
01-28-2011 03:11 AM
hah no problem at all! yeah i agree scale9grid info is scarce compared to other things around here. but one reason for that is prolly that scale9grid is a grey area from what i've read about it so far in AS3. it basically doesnt do what logically makes sense. people feel it should do one thing but it really does another. but as with all things intangible there are workarounds ![]()