views:

304

answers:

1

Hi! I'm using Ming to create an library swf, using the first code example below. How can I access the embedded png from my Flex application? Here's the php/ming code:

<?php
// Ming to create Library.swf
//-----------------------------------
// Create background...
Ming_setScale(20.0000000);
$movie = new SWFMovie();
ming_useswfversion(7);
$movie->setDimension(550,400);
$movie->setBackground(200, 200, 200);

// Load png file...
$img_file = "src/assets/page0.png";
$png = new SWFBitmap(fopen($img_file, "rb"));

// Add png to movie...
$movie->add($png);

// Export png
$movie->addExport($png, 'png');
$movie->writeExports();

// Save movie to swf
$swfname = dirname(__FILE__);
$swfname .= "/bin-debug/Library.swf";
$movie->save($swfname, 9);

?>

And here's my flex essay:

// Loading Library.swf (works), trying to access png asset (doesn't work)    
private var loader:Loader = new Loader();
private function onCreationComplete():void {
 loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
 loader.load(new URLRequest('Library.swf'));
}
private function onComplete(e:Event):void {
 var resourceClass:Class = loader.contentLoaderInfo.applicationDomain.getDefinition("png") as Class;
}

I'm not sure that the png is exported properly. Testing the Library.swf with SwfUtils code (swfutils.riaforge.org) doesn't show any exported classes at all. Or maybe something else is wrong?

A: 

Hi, well I have the same problem I create a library with ming and try to access it from flex and doesn't work.

I've only used this because I needed somehow for an certain url using the Loader class to retrieve the Class object that I can use it to set backgroundImage for a Canvas for example.

But I think that swf exported by ming my have a lower version than the flex compiled swf, and it can't recognize the embedded class name unfortunately.

Hi zmoky! Ming seems to be dead end for this, unfortunately, because it exports the symbols but not the needed class stubs. The same is true for other tools like SwfMill. Using Zend's AMF libraries, it's possible to create a bytearray data bunch wich can contain anything including graphics. Have a look at Robert Tylor's blog: http://www.roboncode.com/articles/144.
Cambiata