0 Replies Latest reply on Dec 6, 2011 7:47 AM by clem_c_rok

    Flexunit + Parsley - re-creating error: "Object of type is already managed"

    clem_c_rok Level 1

      Hello,

         This may sound a bit strange but I'm trying to force an "Object of type is already managed" error to recreate a bug we had in our app for

         flexunit testing purposes.   The problem arised when we upgraded to FB 4.5 and had a double parsley configuration in a popup launched from a module.

         Here's my flexunit test:

       

       

      [code]

      [Test]

      public function testReportsPrintDialog1():void

      {

                rpDialog = new ReportsPrintDialog();

       

                //attempting to forcibly re-create the project-70 bug:

                //"Object of type reportsDirectoryModule.views::ReportsPrintDialog is already managed"

                childContext.viewManager.addViewRoot(reportsDirectoryBase);

                childContext.viewManager.addViewRoot(rpDialog);

       

                trace("rpDialog: " + GlobalState.objects.isManaged(rpDialog));

                trace("reportsDirectoryBase: " + GlobalState.objects.isManaged(reportsDirectoryBase));

       

                rpDialog.addEventListener(FlexEvent.CREATION_COMPLETE, onCreationComplete, false, 0, true);

                PopUpManager.addPopUp(rpDialog, DisplayObject(FlexGlobals.topLevelApplication));

      }

      [/code]

       

       

      Unfortunatly, my attempts at 'forcing' the extra parsley object managment by using addViewRoot is not reproducing the error.

       

       

      In my test suite I am setting up my main and module scoped parsley context in the next code snippit and it has

      been working very well for other tests so far. Here's the context setup code:

       

       

      [code]

      import reportsDirectoryModule.parsleyConfig.ParsleyConfig;

      public var context:Context;

      public var childContext:Context;

       

       

      //create base TDMSE parsley context

      this.context = ContextBuilder.newBuilder()

                .config(FlexConfig.forClass(TDMSEAppParsleyConfig))

                .object(this)

                .build();

       

       

      this.childContext = ContextBuilder

                .newSetup()

                .parent(context)

                .newBuilder()

                .config(FlexConfig.forClass(reportsDirectoryModule.parsleyConfig.ParsleyConfig))

                .build();

      [/code]

       

       

       

       

      The ReportsPrintDialog actually inherits from a base popup class called ReportsDirectoryBase which has this parsley declaration:

      [code]

      <s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009"

                                              xmlns:mx="library://ns.adobe.com/flex/mx"

                                              xmlns:s="library://ns.adobe.com/flex/spark"

                                              xmlns:parsley="http://www.spicefactory.org/parsley"

                                              skinClass="common.skins.TitleWindowSkin">

       

                <fx:Declarations>

                          <parsley:ContextBuilder id="childContext"

                                    parents="{app.module.getContext()}" domain="{app.applicationDomain}"/>

                          <parsley:Configure />

                </fx:Declarations>

                <fx:Script>

                          <![CDATA[

                                    import mx.core.FlexGlobals;

                                    [Bindable]

                                    private static var app:Object = FlexGlobals.topLevelApplication;

      [/code]

       

       

      And the 'Object of type is already managed' exception was because ReportsPrintDialog had the following Configure declaration:

       

       

      [code]

      <rdv:ReportsDirectoryBase xmlns:fx="http://ns.adobe.com/mxml/2009"

                                              xmlns:s="library://ns.adobe.com/flex/spark"

                                              xmlns:mx="library://ns.adobe.com/flex/mx"

                                        xmlns:rdv="reportsDirectoryModule.views.*"

                                              xmlns:cc="common.components.*"

                                              xmlns:parsley="http://www.spicefactory.org/parsley"

                                              title="Print Reports Confirmation"

                      width="300"

                                              creationComplete="init()"

                                              showCloseButton="true"

                                              close="closeWindow()">

       

                <fx:Declarations>

                          <parsley:Configure/>

                </fx:Declarations>

      [/code]

       

       

      I know this is a bit strange, but if nothing else, I'm chalking it down as a good flexunit/parsley learning experience.

       

       

      Thanks,

      Eric H