Yeah, nothing in the namespace of the 'library' swf seems to come in,
you have to reach in and
get them, and only then the publicly declared properties. The library
swf itself in this case is just
compiled as a regular app.

Another option the flex compiler has is tht you  can compile against
one or more .swc libraries, and say you want them to be treated
'runtime shared libraries", however this seems to cause the libraries
to get loaded  (over the network) when the app loads ,automatically.
There does not seem to be any option to defer the loading in that
case.


On Fri, Nov 14, 2008 at 5:53 PM, P T Withington <[EMAIL PROTECTED]> wrote:
> This looks like the right approach to me.
>
> So, is a Library like a module?  Only the public things are accessible?
>  Does this help to make it so you don't need namespaces?  I.e., you are
> importing the library CircleClass and 'renaming on import' to lz.circle
> which keeps it from colliding with any CircleClass you might have already
> had.  (Change CircleClass to Window and maybe it is more meaningful.)
>
> On 2008-11-14, at 17:12EST, Henry Minsky wrote:
>
>> The following is a piece of as3 code which loads a class library at
>> runtime. This example was built from an example in the AS3 docs for
>> Class.
>>
>> It works by defining a "Library" class which declares some public vars
>> which are bound to classes. When the main app loads this library swf,
>> it has access to the library object via the loader's 'content' field,
>> and from that it can grab the class bindings.  This example works for
>> me, so
>> I am thinking of implementing the <import> feature using this. All of
>> the classes which are defined inside of an <import> will be listed
>> in a library class, and when loaded, pointers to the classes will get
>> copied to the lz dictionary.
>>
>> Resources can be embedded the same way, but will be copied to the main
>> app resource tables.
>>
>>
>>
>> Main.as:
>>
>> package {
>>  import flash.display.*;
>>  import flash.events.*;
>>  import flash.net.*;
>>  import flash.utils.*;
>>  import flash.system.*;
>>
>>   public class Main extends Sprite {
>>
>>       public var libname:String = "MyLibrary.swf";
>>       public var loader:Loader = null;
>>       public var lz:Object = {};
>>
>>
>>       public function Main () {
>>
>>           // Load the library named "MyLibrary.swf" at runtime
>>           var request:URLRequest = new URLRequest(libname);
>>           request.method = URLRequestMethod.GET;
>>           this.loader = new Loader();
>>           var info:LoaderInfo = loader.contentLoaderInfo;
>>           info.addEventListener(Event.COMPLETE, addNew);
>>           this.loader.load(request);
>>       }
>>
>>
>>       public function addNew(event:Event):void {
>>           var library:Object = event.target.content;
>>           // grab the class bindings we defined out of it
>>           lz.circle = library.circleCelass;
>>           var circle:Shape = new lz.circle(0xffccaa, 20);
>>           addChild(circle);
>>       }
>>   }
>> }
>>
>>
>>
>> MyLibrary.as:
>>    package {
>>     import flash.display.Sprite;
>>     public class MyLibrary extends Sprite {
>>
>>         public var circleClass:Class = Circle;
>>         public var clickyClass:Class = Clicky;
>>         public function MyLibrary() {
>>         }
>>     }
>>    }
>>
>>    import flash.display.Shape;
>>    class Circle extends Shape {
>>     public function Circle(color:uint = 0xFFCC00, radius:Number = 10) {
>>         graphics.beginFill(color);
>>         graphics.drawCircle(radius, radius, radius);
>>     }
>>    }
>>
>>
>>
>>
>>
>> --
>> Henry Minsky
>> Software Architect
>> [EMAIL PROTECTED]
>
>



-- 
Henry Minsky
Software Architect
[EMAIL PROTECTED]

Reply via email to