Exemplo n.º 1
0
        private void OverrideFlexAppModuleFactorySetter(AbcInstance instance)
        {
            Debug.Assert(IsFlex4);

            var moduleFactoryInitialized   = instance.DefineSlot("__moduleFactoryInitialized", AvmTypeCode.Boolean);
            var flexModuleFactoryInterface = _generator.ImportType(MX.IFlexModuleFactory);

            var propertyName = Abc.DefineName(QName.Global("moduleFactory"));

            instance.DefineMethod(
                Sig.set(propertyName, flexModuleFactoryInterface).@virtual().@override(),
                code =>
            {
                code.Trace("PFC: setting FlexModuleFactory to application");

                // super.moduleFactory = value
                code.LoadThis();
                code.GetLocal(1);
                code.SetSuper(propertyName);

                code.LoadThis();
                code.GetProperty(moduleFactoryInitialized);
                var br = code.IfFalse();
                code.ReturnVoid();

                br.BranchTarget = code.Label();

                code.LoadThis();
                code.Add(InstructionCode.Pushtrue);
                code.SetProperty(moduleFactoryInitialized);

                CallInitStyles(code, instance);

                // init application after styles are initialized
                var ctor = instance.FindParameterlessConstructor();
                if (ctor != null)
                {
                    var ctorMethod = _generator.MethodBuilder.BuildAbcMethod(ctor);
                    code.LoadThis();
                    if (AbcGenConfig.FlexAppCtorAsHandler)
                    {
                        code.PushNull();
                    }
                    code.Call(ctorMethod);
                }

                code.ReturnVoid();
            });
        }