PDA

View Full Version : dynamic library


vangun
06-11-2005, 06:18 PM
I want to know the tradeoffs for instantiating a class using tags (<myclass/>) versus instantiating in script (new myclass).
I want to use dynamic loading of libraries using the <import> tag with stage="defer" to reduce the size of my application. This implies that I have to instantiate the classes in script since dynamic loading does not work when using tags. Will performance be affected ?

Thanks for your help.

hqm
06-11-2005, 06:27 PM
There's no difference in performance whether you instantiate a view in script or as a tag; the tags just get compiled down to calls to instantiate views. There are constraints and other complex attributes however which can only be compiled in to tag calls, or at least it is more difficult to do that in script.

You can actually have calls to tags in your main app which are only defined in a dynamically loaded library, as long as you don't actually try to instantiate them until the library is loaded.

So for example you could say

<class name="myclass">
<mytagfromlibrary/>
</class>

<import href="mylibrary.lzx"/>

If mylibrary.lzx defines the class "mytagfromlibrary", then you can issue calls
to

new myclass()

in your script, and they will instantiate properly as long as you have loaded the library before doing so.


Note: If you are going to be using <import>, should get the latest nightly build, we fixed several serious bugs in dynamically loaded libraries since the 3.0 release. The bugs affected things like event handlers and constraints which would randomly shadow other ones from the main app or other libraries, amongst other things. A unique-id generator was getting reset for each library, causing aliasing of symbols for anonymous functions.