Hi iiley,
> But i really confused why MMC got a wrong initialization order,
> i can't reduce to a little sample to review the problem.
The problem is, your code results in two contradicting initialization
orders.
One order is defined by the class hierarchy. In prototype based oop the
class prototype has to be created before it can be extended. Normally
the compiler should be able to find this order by creating a tree of the
"extends" hierarchy and initialize the classes from the root to the
leaves. As long the classes there are no circular references, like A
extends B and B extends A, this order is correct. Afaik MMC gives you a
warning if there are circular references.
The other order is determined by the static initializations, which
depend on other classes, eg. like static var x = new ClassY() or static
var x = ClassY.staticProperty; ClassY needs to be initialized before
this can run.
Now as we know this, it's simple, to create an example, which breaks
this logic.
class A extends B {}
class B { static var x = new A() }
Following the extends hierarchy creates a sequence of B->A, while
following the static initializations gives you A->B. The dilemma become
obvious now. The compiler can't decide the correct initialization order.
The solution i described earlier, is to move all your static
initializations into a static init method and call this method after the
class hierarchy has been initialized. A good place would be to call it
first in the public static main entry point.
One question remains though. Why is mtasc able to compile it correctly.
This could either be a coincidence, because the compiler chooses a
working order by chance or mmc really has a bug. I'm not sure about it.
Cheers,
Ralf.
iiley wrote:
>>You can't really force it easily.
>>All you can do is "not to disturb" MMC finding out the correct order.
>
>
> Yes, you are right, it's a very hard thing, and i really "disturbed" MMC, i
> make a class with a static function and a static var like this:
>
> class InitializePre{
> static function initializeClass():Boolean{
> var t = EventDispatcher;
> t = Component;
> t = Container;
> return true;
> }
>
> static var classInitialized:Boolean = initializeClass();
> }
> And removed getRootMCPanel function from MCUtils class. Then i ran
> test.AccordionTest after a line code: var t = InitializePre. amazed, MMC
> find the right order, and the component runs. all thing goes well.
> But the sad thing is, this is just a "disturbed" situation, it is strange,
> even Flash.exe and FlashPlayer.exe got different show with the published
> swf.:) in flash.exe, the compiled component runs well, but when i run it in
> flashPlayer.exe, i see the jframe scaled to be a little dot, don't know
> where is the other components. Weird.Depressed.
>
>
>
>>What i would try, is putting all initializations of static variables
>>which rely on other classes into a method and call this method explicitely.
>
>
> class ClassA {
> static var prop:ClassB;
>
> static function initializeClass(){
> prop = new ClassB();
> }
> }
>
> Thank you for tell me this cool way Ralf, but this is just to ensure the
> prop get right value created, am i right? In AsWing there are less situation
> about this, and the point of issue MCPanel, there is not any static MCPanel
> var.
>
> MMC is too evil, the way i can imagine just to avoid this issue( or just
> don't support MMC?), i have to test a lot to make this do not happen again.
> Maybe i need remove MCPanel classes. But i really confused why MMC got a
> wrong initialization order, i can't reduce to a little sample to review the
> problem, if i want Adobe to help me, i would not send them a big project
> like ASWing, there are hundreds classes. Must be hard to test if they have
> never read these codes.
>
>
> 2005/12/9, Ralf Bokelberg <[EMAIL PROTECTED]>:
>
>>You can't really force it easily.
>>All you can do is "not to disturb" MMC finding out the correct order.
>>
>>What i would try, is putting all initializations of static variables
>>which rely on other classes into a method and call this method
>>explicitely.
>>
>>class ClassA {
>> static var prop:ClassB;
>>
>> static function initializeClass(){
>> prop = new ClassB();
>> }
>>}
>>
>>class ClassB {
>> static var prop:ClassC;
>>
>> static function initializeClass(){
>> prop = new ClassC();
>> }
>>}
>>
>>class ClassC {
>>
>>}
>>
>>class ClassMain {
>>
>> static function main(){
>> initializeClasses();
>> }
>>
>> static function initializeClasses(){
>> ClassA.initializeClass();
>> ClassB.initializeClass();
>> }
>>}
>>
>>This is a lot of work to do and i'm not sure if it works, but maybe you
>>give it a try.
>>r.
>>
>>
>>
>>--
>>iiley
>>AsWing http://www.aswing.org
>>Blog http://spaces.msn.com/members/iiley/
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> osflash mailing list
> [email protected]
> http://osflash.org/mailman/listinfo/osflash_osflash.org
_______________________________________________
osflash mailing list
[email protected]
http://osflash.org/mailman/listinfo/osflash_osflash.org