[swfmill] Accessing swfmlill library assets (png, mp3) from Flex/as3

armencho at gmail.com armencho at gmail.com
Thu Nov 5 07:37:00 PST 2009


2009/11/4 Jonas Nyström <jonasnys at gmail.com>:
> Hello!
>
> I would like to replace my flex-compiler library creation with swfmill. My
> problem is that I've not been able to
> access any of my swfmill library assets. (In my current project i need png
> images and mp3 soundfiles.)

It is possible, although abstractions are quite different. For example
I use the following xml which is compiled with "swfmill simple
assets.xml ../lib/assets.swf"

<?xml version="1.0" encoding="utf-8" ?>
<movie version="10">
	<frame>
		<library>
			<bitmap id="mypackage.MyImage"
				import="assets/gui/images/myimage.png" />
			<font id="helvetica-neue-heavy"
				import="assets/fonts/HelveticaNeueLTCom-Hv.ttf" />
		</library>
	</frame>
</movie>

Since Flex does not have a facility to "fuse" two SWFs together, you
will have to load the swf compiled by swfmill at runtime. However,
from then it is pretty simple - load it on the fly into the same (or
different, how you prefer) application domain and get the class
definition:

var MyImage = flash.utils.getDefinitionByName("mypackage.MyImage");

var img_obj = new MyImage();

You can also try to include a source code along with your app which will:

package mypackage
{
     extern class MyImage, extends flash.display.BitmapData
     {
     }
}

If you are loading into another application domain, use
ApplicationDomain.getDefinition in the same manner.

>
> This is how I create my Library.swf from a as3 class right now using flex
> compiler:
>
> package {
>     import flash.display.Sprite;
>     public class Library extends Sprite    {
>             [Embed(source="assets/test.png")]
>             public var TestPng:Class;
>             [Embed(source="assets/test.mp3")]
>             public var TestSound:Class;
>     }
> }
>
> (This library creation is what I want to replace with a swfmill solution.)
> The library is later used in my Flex app in the following way:
>
> private var loader:Loader = new Loader();
>
> private function onCreationComplete():void {
>     this.loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
> onComplete);
>     this.loader.load(new URLRequest('assets/Library.swf'));
> }
>
> private function onComplete(e:Event):void {
>     var resourceClass:Class =
> loader.contentLoaderInfo.applicationDomain.getDefinition("Library") as
> Class;
>     var resources:Object = new resourceClass();
>
>     // Png bitmap
>     var symClass:Class=resources['TestPng'] as Class;
>     var testBitmap:Bitmap = new symClass() as Bitmap;
>     this.rawChildren.addChild(testBitmap);
>
>     // Sound
>     symClass = resources['TestSound'] as Class;
>     var testSound:Sound = new symClass() as Sound;
>     testSound.play(0);
> }
>
> Is it possible to create a swfmill Library.swf that has the same structure
> and can be accessed the same way as my as3 library above? If not, could
> anyone explain how to create and access images and mp3s in a corresponding
> way?
>
> Regards / Jonas
>
> _______________________________________________
> swfmill mailing list
> swfmill at osflash.org
> http://osflash.org/mailman/listinfo/swfmill_osflash.org
>
>



More information about the swfmill mailing list