My testbed is able to composite a thousand elements into clips on screen, but I can't extract a bitmap on the fly from an external swf for Starling or for export to png.
(I'm a bit of a code butcher, but have tried lot of variations and have looked through spritesheet generating examples))
I have seen the advice "You can't get bitmapData from a Class only displayObjects (MClip, Sprite)", My line: s = new AssetClass() below seems to address that. Correct usage of addtoStage when loading external swf
I am able to generate a bitmap of an internal vector movieclip, and save it to a .png using as3corelib.PNGEncoder.as, but I end up with a blank png using clips from the external swf, running this in Flash Pro CC..
paraphrased code:
// swf load done handler:
testBitmap = new Bitmap(new BitmapData(w, h , true, 0x0));
var AssetClass:Class = getDefinitionByName("assetNameFromDatabase") as Class;
var s:MovieClip = new AssetClass(); // AddChild(s) functions properly
var m:Matrix = new Matrix(1, 0, 0, 1, 400, 300);
testBitmap.bitmapData.draw(s, m);
// addChild(testBitmap); or send to PNGEncoder rsult is blank
// internal clip test that does convert to bitmap
var b:MovieClip = new testdMovieClip();
var m:Matrix = new Matrix(1, 0, 0, 1, 200, 300);
testBitmap.bitmapData.draw(b, m);
//----------------------------
Thanks Vesper, Couldn't gfix things with your suggestion, I was actually already adding to a movieClip, just left it out of the simplified code sample, I did try some variates of adding an instance ahead of drawing to bitmap, still getting no results.
//--
*** Amendment: Looks like the libs have embedded "display but don't copy" protect code? can someone verify this.
I am using merged movieclip libraries provided in swf format, (I have individual fla source for the hundreds of resources in the library swfs that I hoped to avoid dealing with, their removing swf import from Flash Pro cc is a further agrrevation) This is public domain material from a retired game.
Using a Trillix trial, I examined the embedded Class files, along with the usual individual asset Class they had this code:
public override function get movieClipData():flash.utils.ByteArray
{
if (bytes == null)
{
bytes = flash.utils.ByteArray(new dataClass());
}
return bytes;
}
{
bytes = null;
}
internal static var bytes:flash.utils.ByteArray=null;
// the classes also have
import flash.utils.*;
import mx.core.*; // as well as embedded package mx files, is that for Flex?
I was looking at creating some code-less external library files for Air/iOS down the road, I may have to learn to ways to auto merge FLAs sooner than later.