AS3 Embed Image Instead of drawing graphics
I've got a custom AS3 scrollbar that I need to modify. The scroll thumb (the draggable part of a scrollbar) is currently just done by drawing a rectangle. But I need it to look more like a real scrollbar. Not sure how to modify the below code to import/use a scroll thumb image:
scrollThumb = new Sprite();
scrollThumb.graphics.lineStyle();
scrollThumb.graphics.beginFill(0x0066ff);
scrollThumb.graphic开发者_C百科s.drawRect(0, 0, 1, 1);
addChild(scrollThumb);
I know that I would embed an image by doing something like this:
[Embed(source="images/image1.png")] private static var Image1Class:Class;
But then how do I set the scrollThumb = to the image?
Thanks!
Images get called in as BitmapDatas so you need to do
addChild(new Bitmap(new Image1Class(0, 0)));
or if you want to manipulate it as a Sprite:
scrollThumb = new Sprite;
scrollThumb.addChild(new Bitmap(new Image1Class(0, 0)));
addChild(scrollThumb);
I think it should be as simple as:
scrollThumb = new Image1Class() as Sprite;
addChild(scrollThumb)
精彩评论