8 Replies Latest reply on Jul 3, 2010 9:08 PM by archemedia

    CreationComplete called twice

    srinivas38

      Hi,

      I have a custom mxml itemrenderer to tilelist working with flex3.0.The itemrenderer  creationComplete event is fired two times.Why this is happening so.Then how to handle it.Your help is appreciated.

      Thanks,

      Srinivas

        • 1. Re: CreationComplete called twice
          archemedia Level 4

          Hi, Could you post some code?

          -Dany

          • 2. Re: CreationComplete called twice
            srinivas38 Level 1

            Hi,

            This is my bit of code:

             

             

            <mx:ViewStack id="vsMain" width="100%" height="100%">

                

            <mx:Panel id="pnlLogin" ></mx:Panel>

             

            <mx:Panel id="pnlVideo" width="100%" height="100%">

                

            <mx:TileList

             

            id="tileList"

            dataProvider="{dpUsers}"

            columnCount="{getRC(dpUsers.length,'col')}"

            rowCount="{getRC(dpUsers.length,'row')}"

            itemRenderer="custom.comp.customMXMLItemRenderer"

            width="100%" height="100%">

             

             

             

             

            </mx:TileList>

            </mx:Panel >

            </mx:ViewStack >

             

            /////custom mxml itemrender "customMXMLItemRenderer"

            <?xml version="1.0" encoding="utf-8"?>

            <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"

             

            horizontalAlign="center" width="100%" height="100%"

            verticalAlign="middle"

            backgroundColor="#E4E0E0"

            creationComplete="playVideo()">

             

            private function playVideo():void{

            trace(data.isSender);

            if(data.isSender){

                 ....video dispalay....statements

            }

            </mx:VBox>

            /////////////////////////////////////

            in the above code when I run the application "Error #2044: Unhandled NetStatusEvent:. level=error, code=NetStream.Publish.BadName"

            is generated and when i dismiss the video is played.The trace statement shows two times output.And the dataprovider lenth is only one.

            Thanks

            Srinivas

             

             

             

            • 3. Re: CreationComplete called twice
              archemedia Level 4

              Hi,

              first a few debugging tips:

               

              There are two errors here, one regarding the video playback and the other regarding the creationComplete event. Tackle them seperately:

               

              - disable the code within the playVideo function to isolate the creationComplete issue. Leave the trace statement

              - put a breakpoint on the trace statement and debug the application.

              - When the debugger pop up, you should be within the playVideo function

               

              Do you enter this function twice?

              If so, look at the stack window in you debugger to see where the creationComplete event was fired.

               

              I suppose dpUsers is set within a result handling function? Try to add a test line in this function and call both getRC(dpUsers.length,'col') and getRC(dpUsers.length,'row'). These should return 1 in both cases.

               

              If this isn't clear to you, just let me know.

               

              Dany

              • 4. Re: CreationComplete called twice
                srinivas38 Level 1

                Hi Danny,

                I debugged the  application by keeping break point in playVideo().It is still displaying two times trace values.

                Again I also removed both the getRC(dpUsers,"col") and getRC(dpUsers,"row") from tilelist calling there.The trace statement in itemrenderer still prints two times.I also called the getRC() methods from resultHandler function by removing from tilelist, from there getRC() methods are called only once.

                I heared that custom itemrender creationCompete event is having bug.But I din't find any solution to resolve it.Though the creationComplete event is fired twice the video is displayed.But in long run the application may hit buggs.So Please find a solution or any logic to clear it out.

                Thanks,

                Srinivas

                • 5. Re: CreationComplete called twice
                  archemedia Level 4

                  You could create a workaround to see if it works then:

                   

                  private var initialized:Boolean = false;

                   

                  private function playVideo():void

                  {

                       if (!initialized)

                       {

                            initialized = true;

                            //further code. this ensures that this handler is called only once!

                       }

                  }

                   

                  Dany

                  • 6. Re: CreationComplete called twice
                    srinivas38 Level 1

                    Hi,

                    I tested the simple example with itemrenderer:

                    ////////Application////////////

                    <?xml version="1.0" encoding="utf-8"?>

                    <mx:Application

                     

                     

                    xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns="*">

                     

                     

                     

                    <mx:Script>

                    <![CDATA[

                     

                     

                    import mx.collections.ArrayCollection;

                     

                    [

                    Bindable]

                     

                    private var tlAC:ArrayCollection = new ArrayCollection([{name:"xyz"}]);

                     

                    ]]>

                     

                    </mx:Script>

                     

                     

                    <mx:Panel id="pnlVideo" width="100%" height="100%">

                     

                     

                    <mx:TileList id="tileList"

                    dataProvider="

                    {tlAC}"

                    itemRenderer="

                    MyitemRenderer"

                    width="

                    100%" height="100%" useRollOver="false"

                    selectionColor="

                    #444343"

                    verticalScrollPolicy="

                    off"

                    borderStyle="

                    solid" backgroundColor="#444343" >

                     

                     

                    </mx:TileList>

                     

                     

                     

                    </mx:Panel>

                    </mx:Application>

                    ////////////////////////////////

                    MyitemRenderer component

                    /////////////////////////////////////

                    <?xml version="1.0"?>

                    <!-- itemRenderers\inline\myComponents\RendererDGTitleImage.mxml -->

                    <mx:VBox

                     

                    xmlns:mx="http://www.adobe.com/2006/mxml"

                    horizontalAlign="

                    center" height="75" creationComplete="init()" >

                     

                     

                    <mx:Script>

                    <![CDATA[

                     

                    private var isInit:Boolean;

                     

                    private function init():void{

                     

                    if(!isInit){

                     

                    trace("init....");

                    isInit=

                    true;

                    }

                     

                    }

                     

                    ]]>

                     

                    </mx:Script>

                    </mx:VBox>

                    The above example also prints two times.

                    Thanks

                    Srinivas

                    • 7. Re: CreationComplete called twice
                      archemedia Level 4

                      ok, I'll give this a test

                      • 8. Re: CreationComplete called twice
                        archemedia Level 4

                        I can't give you a solution yet, but I can tell you what causes the  problem:

                         

                        what's happening is that your first itemRenderer will be 'created' twice because of (I think) setup and measuring purposes (you can clearly see the differences in the execution stacks).

                        Because of recycling of item renderers, you shouldn't use a creationComplete event! Instead, override the data property of an itemRenderer, like this:

                         

                        override public function set data(value:Object):void
                                    {
                                        super.data = value;
                                    }

                         

                         

                         

                        Here's a link to an article which might get you further or at least give you further insight:

                         

                        http://stackoverflow.com/questions/645323/how-do-i-stop-a-datagrids-first-row-itemrenderer -from-instantiating-adding-initi

                         

                        If I run into a solution, I'll post it.

                         

                        Dany