Starling AS3 -- How To Use Bitmap Objects in SWC - actionscript-3

I'm trying to see how Starling could benefit the applications I build using as3. My knowledge thus far of Starling is that it only uses bitmap objects not symbol objects. How do I take a BitmapData class and create an starling Image out of it.
This bitmap was a symbol in flash that was converted into bitmap. It then had its properties modified to export for as3
Say there is a Ship BitmapData class in a swc.
According to Starlings documentation of how it handles other bitmap like a png, I would think I should be able to do this.
var myShip:Image = Image.fromBitmap(new Ship());
This of course doesn't work.

fromBitmap() expects to receive a bitmap object but here you are passing in a BitmapData Class. And Image class requires a texture.
Also your syntax is slightly incorrect.
NB. There is Texture.fromBitmap and Texture.fromBitmapData.
Although I haven't tried accessing assets from a swc you could try:
var myShip:Image = new Image(Texture.fromBitmapData(new Ship());
Perhaps try to get the Image appearing first before attempting to access the swc bitmapData
var bd:BitmapData = new BitmapData(100, 100, false, 0xFF0000);
var myShip:Image = new Image(Texture.fromBitmapData(bd);
addChild(myShip); //should display a red square

Related

Extract bitmap (or bitmapdata) from Shape

I got an swf that has SimpleButtons in the stage, and I need to get the bitmap or bitmapdata information from the button states.
When I load the symbol, it seems that no matter what composes the button states, they are all shapes, at least that's what I get in the expression panel.
So, how can I get the bitmap or bmpdata from a Shape?.
Thanks.
You can use BitmapData#draw() to get BitmapData from any DisplayObject. BitmapData is raster, so be aware you will lose features of the vector Shape
var bd:BitmapData = new BitmapData( shape.width, shape.height );
bd.draw( shape );
If you're targeting FP 11.6 I'd use the method graphics.readGraphicsData as explained here http://www.bytearray.org/?paged=6

Converting MovieClip to Bitmap with Dispose()

I am working on a mobile game using Flash CS6 with AIR. also design and coding on same platform (not using starling etc.).
I am converting movieClips (static, not animated) to bitmap dynamically and its working fine. But i realize with this process bitmapData caching on memory and with big shapes it takes a lot of memory. Then i decide to after added to stage clear to bitmapData by dispose(). But its removes from stage and anywhere its shown.
My code;
var target:MovieClip = new Ex_mc2();
target.x=100;
target.y=300;
addChild(target);
var bounds:Rectangle = target.getBounds(this);
var bmpData:BitmapData = new BitmapData(Math.floor(bounds.width), Math.floor(bounds.height), true, 0);
var bmpMatrix:Matrix = target.transform.matrix;
bmpMatrix.translate(-bounds.x, -bounds.y); // Draw bitmap
bmpData.draw(target, bmpMatrix);
var bmp:Bitmap = new Bitmap(bmpData);
bmp.x=100;
bmp.y=300;
addChild(bmp);
removeChild(target);
//bmpData.dispose(); I want to use this and i dont want my bmp disappear
Searching to solution for one week but i cant figure it out.
So my question is;
Can i converting movieClips to bitmap with freeing to memory? Like adding stage a static png file?
BitmapData -- is actually what's being shown on the screen. The format is almost identical to BMP, but the order of bytes is reversed. Bitmap is only a display container, serving to output image content to the screen and providing common DisplayObject APIs.
So, if you use BitmapData.dispose(), you are actually freeing the memory occupied by image and obviously after that there is nothing to be shown by Bitmap container.

Starling - load SWF image(vector) into a Image

I'm trying to convert an old project of mine to use Starling for some extra performance.
I've come to a problem when I'm loading my SWFs and trying to display them.
Here is the code I used before: (no Starling)
private function swfLoaded(e:LoaderEvent):void {
var spr:Sprite = new Sprite();
spr = e.currentTarget.content;
bitmapData.draw(spr ...);
}
The problem when I'm using Starling is that the currentTarget.content is a flash.display.displayObject.
cannot convert com.greensock.loading.display::ContentDisplay#90ffec1 to starling.display.Sprite
I want to find a way to "convert" the flash.display.displayObject into a starling Sprite.
I also want to be able to store the loaded swfs content into a array as a sprite.
Thanks in advance,
Tompa
You're overwriting spr with a different value immediately after you create it, for one thing.
After you do the bitmapData.draw() call:
var tex:Texture = Texture.fromBitmapData(bitmapData, false, false);
The new texture can then be used to create a Starling Image sprite.

Make mask visible in ActionScript 3.0

I have Loader object containing loaded swf. I don't know how the shape of this swf looks like - it's not necessarily rectangular.
I want to add some light reflection on it. I need to mask this reflection with Loader, but in the same time I need this Loader to be visible.
I don't want to load swf twice, because it may contain some dynamic, script-generated content, which can produce different results in each Loader.
And that's quite a problem, isn't it? Any ideas?
Image: http://www.freeimagehosting.net/uploads/12e6b9cd63.jpg
you could add your instance of the loaded swf to the stage, and for the reflection use he same movieclip/sprite and draw it to a new BitmapData. do the transformations needed and then add to stage.
Or imagine the following situation, instead of having the swf that is loaded adding it's own graphics to library you could do this from the loading application, so for instance, give the instance name of MyDisplayObject to the movieclip in the loaded swf and export to actionscript. After you load the swf you could use the following code to access the library, so you can add this object number of times you need, in you case 2.
here is the code (from adobe live docs)
function initHandler(e:Event) {
var applicationDomain:ApplicationDomain = e.target.applicationDomain; // e.target is the loaderInfo object
var testClip:Class=applicationDomain.getDefinition("testClip") as Class;
var clip = new testClip();
addChild(clip);
var reflection = new testClip();
addChild(reflection);
reflection.y= 100;
}
Hope this get's you on the right track.

Screendump from within Actionscript 3.0 is it possible or?

We have Bitmap and Bitmapdata objects now. And when using the webcam, we can get raw-pixeldata output from it. But, can we get raw-pixeldata from the "stage" or "swf" object somehow?
I would like to use this to make "small thumbnails" of certain parts of Actionscript applications and these could be complex compositions of dynamic text, bitmap graphics and movieclips at the same time. So it would be nice to make a "quick snap" and just get the current combined pixels into one bitmap and then be able to "save that for later use".
Is that possible? is it too easy? am I just looking the wrong place in the Adobe Docs?
We have images, vectors etc at the same time on stage, so I need to grab the "stage" objects bitmapdata???
Create a BitmapData and call its draw() method with the corresponding DisplayObject
var bmpData:BitmapData = new BitmapData(sprite.width, sprite.height, true);
bmpData.draw(sprite);
If you want to make thumbnails smaller, create a Matrix and call its createBox method with required scaling parameters and pass it to the draw method.
var bmpData:BitmapData = new BitmapData(thumbW, thumbH, true);
var mat:Matrix = new Matrix();
mat.createBox(thumbW / sprite.width, thumbH / sprite.height);
bmpData.draw(sprite, mat);