5 Replies Latest reply on Jun 14, 2010 6:12 AM by BhaskerChari

    Get BitmapData of non-rendered component

    UbuntuPenguin Level 4

      TL;DR Non-viewed (but creationPolicy="all') tab in tabnavigator has a scaledWidth and scaledHeight of 0.  This crashes the ImageSnapshot.captureBitmapData function call at line 206 with an Error #2015. Invalid BitmapData.

       

      Hello Everyone ,

        I have a tab-navigator with some children.  In some cases I need to get the BitmapData ( ImageSnapshot.captureBitmapData.. ) from some of the tabs , even if the user has not looked at them yet.  I have set the creationPolicy="all" on any and everything but to no avail I always get an error #2015 Invalid BitmapData.  But while debugging I noticed that in the ImageSnapshot class there is this line where the values for scaledWidth and scaledHeight are both zero.

       

      //Line 206

      data =

      new BitmapData(scaledWidth, scaledHeight, true, 0x00000000);

       

      I guess since my component hasn't been visualized ( honestly , what part of the component lifecycle is passed over by creationComplete )   , does anyone have any clue as to how to get the BitmapData of a component that "hasn't been looked at" ?

      As always , points will be awarded.

       

      Sincerely ,

        Ubu

       

      Message was edited by: UbuntuPenguin Emphasis

        • 1. Re: Get BitmapData of non-rendered component
          Flex harUI Adobe Employee

          What is the actual width/height of the non-viewed child?  It might not be

          sized yet.

          • 2. Re: Get BitmapData of non-rendered component
            UbuntuPenguin Level 4

            I think that's the case HarUI.  When I step through the code , I see the width and height are still zero.  I found the below code on the internet , it runs like it should , but the height and width of the _pricingView still shows up as zero.  So a component can be fully create and still have dimensions of zero ? *And the plot thickens*

             

             

             

            private var _pricingView:PricingView;

             

            protected function pricingViewHack():void

            {

            _pricingView =

             

            new PricingView();

            _pricingView.visible =

            false;

            _pricingView.width = 400;

            _pricingView.height = 500;

            _pricingView.addEventListener( FlexEvent.CREATION_COMPLETE , pricingViewHackHandler );

            FlexGlobals.topLevelApplication.addElement( _pricingView );

            }

             

             

            protected function pricingViewHackHandler( event:Event ):void

            {

            FlexGlobals.topLevelApplication.removeElement( _pricingView );

            _pricingView.visible =

             

            true;

            _pricingView.horizontalCenter = 0;

            _pricingView.verticalCenter = 0;

            _pricingView.x = 0;

            _pricingView.y = 0;

            _pricingView.percentHeight = 100;

            _pricingView.percentWidth = 100;

            pricingContent.addElement( _pricingView );

            }

             

            Message was edited by: UbuntuPenguin , Cleaned up unnecessary code

            • 3. Re: Get BitmapData of non-rendered component
              Flex harUI Adobe Employee

              I'm not sure what that has to do with the problem.  The ViewStack doesn't

              size non-visible children until just before they are shown for the first

              time.  I'd probably just copy the dimensions of the visible child and call

              setActualSize on the child, then validateNow() before trying a snapshot

              • 4. Re: Get BitmapData of non-rendered component
                UbuntuPenguin Level 4

                Thanks HarUI ,

                  Setting the actualSize and calling validateNow solved the problem.  Looks like I need to read up on lifecycle/drawnig functions and processes.

                • 5. Re: Get BitmapData of non-rendered component
                  BhaskerChari Level 4

                  Thanx HarUI!!

                   

                  It worked like a charm....I also tried to find a solution But couldn't figure it out...

                   

                  Thanks for Sharing....very ineteresting and useful one.

                   

                   

                  Thanks,

                  Bhasker Chari