12 Replies Latest reply on Feb 10, 2010 8:33 PM by bringrags

    DimensionChangeEvent firing twice in a row

    jerryhamby Level 1

      The DimensionChangeEvent seems to fire twice in a row.

      Once for the width and again for the height.

      My thinking it should only fire once.

       

      What is the use case for this behavior?

       

      pPlayer.addEventListener( DimensionChangeEvent.DIMENSION_CHANGE, mDimensionChange );

       

      ============ First event ================

      mDimensionChange [Event type="dimensionChange" bubbles=false cancelable=false eventPhase=2]

      evt.newWidth = 600

      evt.newHeight = 0

      evt.oldWidth = 0

      evt.oldHeight = 0

      evt.currentTarget.width =  600

      evt.currentTarget.height =  0

      evt.currentTarget.view.calculatedWidth =  600

      evt.currentTarget.view.calculatedHeight; =  800

       

      ============ Second event ================

      mDimensionChange [Event type="dimensionChange" bubbles=false cancelable=false eventPhase=2]

      evt.newWidth = 600

      evt.newHeight = 800

      evt.oldWidth = 600

      evt.oldHeight = 0

      evt.currentTarget.width =  600

      evt.currentTarget.height =  800

      evt.currentTarget.view.calculatedWidth =  600

      evt.currentTarget.view.calculatedHeight; =  800

        • 1. Re: DimensionChangeEvent firing twice in a row
          RyanOConnell Level 2

          We'll need more code to diagnose your problem.  It should only be firing once if both are set at once however.  Could you file a bug with your test code?

          • 3. Re: DimensionChangeEvent firing twice in a row
            bringrags Level 4

            Agreed.  I think we've fixed this in the public trunk, but recommend you file a bug anyway just to be safe.

             

            Thanks,

            Brian

            • 4. Re: DimensionChangeEvent firing twice in a row
              jerryhamby Level 1

              FYI, problem still exists in Sprint 8:

               

              ======= Opening

              mDimensionChange [Event type="dimensionChange" bubbles=false cancelable=false eventPhase=2]

              mDimensionChange evt.currentTarget.width =  320

              mDimensionChange evt.currentTarget.height =  0

              ==================================

              mDimensionChange [Event type="dimensionChange" bubbles=false cancelable=false eventPhase=2]

              mDimensionChange evt.currentTarget.width =  320

              mDimensionChange evt.currentTarget.height =  240

              ==================================

               

               

              ======= Closing

              mDimensionChange [Event type="dimensionChange" bubbles=false cancelable=false eventPhase=2]

              mDimensionChange evt.currentTarget.width =  0

              mDimensionChange evt.currentTarget.height =  240

              ==================================

              mDimensionChange [Event type="dimensionChange" bubbles=false cancelable=false eventPhase=2]

              mDimensionChange evt.currentTarget.width =  0

              mDimensionChange evt.currentTarget.height =  0

              ==================================

              • 5. Re: DimensionChangeEvent firing twice in a row
                Edwin van Rijkom

                Sprint 8 doesn't have a DimensionChange event any more: it has been replaced by ViewEvent.MEDIA_SIZE_CHANGE (the spatial and viewable trait have been merged). The base ViewTrait implementation now has a single setMediaSize(w,h) method instead of two separate setters for width and height, so unless media implementations call on the setter method twice (once for each dimension), the problem should be gone.

                 

                Can you confirm that you're still seeing the same problem, but now on the ViewTrait's MEDIA_SIZE_CHANGE event?

                 

                Cheers,

                Edwin

                • 6. Re: DimensionChangeEvent firing twice in a row
                  jerryhamby Level 1

                  ====== firing twice code ============

                  pPlayer.addEventListener(ViewEvent.DIMENSION_CHANGE, mDimensionChange);

                   

                   

                  ====== code per your request ============

                  I now get a compiler error on the addEventListener:

                  pPlayer.addEventListener(ViewEvent.MEDIA_SIZE_CHANGE, mDimensionChange);

                  1119: Access of possibly undefined property MEDIA_SIZE_CHANGE through a reference with static type Class.

                   

                   

                  The online ViewEvent docs don't show a MEDIA_SIZE_CHANGE:

                  DIMENSION_CHANGE

                  Constant
                  public static const DIMENSION_CHANGE:String = "dimensionChange"

                   

                   

                  The ViewEvent.DIMENSION_CHANGE constant defines the value of the type property of the event object for a dimensionChange event.

                  VIEW_CHANGE

                  Constant
                  public static const VIEW_CHANGE:String = "viewChange"

                   

                  Language Version: ActionScript 3.0
                  Product Version: OSMF 1.0
                  Runtime Versions: Flash Player 10, AIR 1.5

                   

                   

                  The ViewEvent.VIEW_CHANGE constant defines the value of the type property of the event object for a viewChange event.

                  • 7. Re: DimensionChangeEvent firing twice in a row
                    jerryhamby Level 1

                    Edwin, the more I look at the online docs compared to your post, the more confused I get.

                     

                    The docs state that ViewTrait has a setMediaDimensions method, that sets the mediaWidth and mediaHeight.

                    Then it dispatches a dimensionChange event. 

                    I don't see a setMediaSize method in ViewTrait, is setMediaSize new in Sprint 9?

                     

                    As I stated before, I do see a ViewEvent.DIMENSION_CHANGE event,

                    which should catch the dispatched event from ViewTrait.setMediaDimensions. Correct?

                     

                    I just can't find MEDIA_SIZE_CHANGE event anywhere in the docs?

                     

                    I would think the docs where up-to-date for Sprint 8, cause DimensionChangeEvent is now ViewEvent.

                    • 8. Re: DimensionChangeEvent firing twice in a row
                      jerryhamby Level 1

                      Sorry for so any posts but all my Christmas shopping is done and I have some free time

                       

                      Another test I ran placed 3 exact sized images inside a SerialElement (Sprint 8):

                      ./images/image4.jpg  600x800

                      ./images/image4.jpg  600x800

                      ./images/image4.jpg  600x800

                       

                      What I'm testing for, is to see if the dimensionChange event gets fired for the last 2 images.

                      My thinking is that it shouldn't fire but once for the first image, cause the other 2 are the same size.

                       

                      The docs state:

                      ViewTrait.setMediaDimensions

                      If either the width or the height differs from the previous width or height, dispatches a dimensionChange event.

                       

                      My test show it fires 3 times. I still see the dimensionChange happening twice for each image.

                      So I get 6 dimensionChange events for 3 images.

                      • 9. Re: DimensionChangeEvent firing twice in a row
                        Edwin van Rijkom Level 2

                        Hi Jerry,

                         

                        This is my bad: the MEDIA_SIZE_CHANGE event has been committed on the trunk, but only after sprint 8 was tagged. You are right to use DIMENSION_CHANGE on working with sprint 8.

                         

                        Cheers,

                        Edwin

                        • 10. Re: DimensionChangeEvent firing twice in a row
                          Edwin van Rijkom Level 2

                          Hi Jerry,

                           

                          Thanks for all the additional info. It sounds like we should keep the bug report on for further investigation after the cristmas break.

                           

                          For now, one thought to add is that the dimension change event signalled by SerialElement on going from one element to the next is technically correct in the sense that in between the previous element being removed and the next being added, the view changes dimensions temporarily (from [800,600] to [0,0] and then back to [800,600] again).

                           

                          Cheers,

                          Edwin

                          • 11. Re: DimensionChangeEvent firing twice in a row
                            jerryhamby Level 1

                            This problem is still not fixed, any hope for Sprint 10?

                             

                            It now has a different name, after all the refactoring, but it's still there. (FM-300  Sprint 7)

                             

                            pPlayer.addEventListener(DisplayObjectEvent.MEDIA_SIZE_CHANGE,mMediaSizeChange);

                             

                            ====================== mMediaSizeChange ========== image

                            mMediaSizeChange [Event type="mediaSizeChange" bubbles=false cancelable=false eventPhase=2]

                            mMediaSizeChange evt.currentTarget.mediaWidth =  600

                            mMediaSizeChange evt.currentTarget.mediaHeight =  0

                             

                            ====================== mMediaSizeChange ========== image

                            MediaPlayerVO mMediaSizeChange [Event type="mediaSizeChange" bubbles=false cancelable=false eventPhase=2]

                            MediaPlayerVO mMediaSizeChange evt.currentTarget.mediaWidth =  600

                            MediaPlayerVO mMediaSizeChange evt.currentTarget.mediaHeight =  800

                             

                             

                            pSerialElement=new SerialElement  ;

                            pSerialElement.addChild(new TemporalProxyElement(3,new ImageElement(new ImageLoader, new URLResource(new URL(ImageMaster.getInstance().pAllImagesArray[0].pURL)))));

                             

                            pSerialElement.addChild(new TemporalProxyElement(3,new ImageElement(new ImageLoader, new URLResource(new URL(ImageMaster.getInstance().pAllImagesArray[1].pURL)))));

                             

                            pSerialElement.addChild(new TemporalProxyElement(3,new ImageElement(new ImageLoader, new URLResource(new URL(ImageMaster.getInstance().pAllImagesArray[2].pURL)))));

                            • 12. Re: DimensionChangeEvent firing twice in a row
                              bringrags Level 4

                              I believe (*crosses finger*) that this is fixed in public trunk.  At least, looking at the code I don't see the duplicate event dispatch that I saw before.  I've marked it as fixed, someone from our QE team will verify.