10 Replies Latest reply on Aug 5, 2010 2:53 PM by Flex harUI

    How do we know when an object is visible?

    Zolotoj Level 3

      If I change visible property how do I know when the object becomes fully visible?

       

      Thanks

        • 1. Re: How do we know when an object is visible?
          rtalton Level 4

          Look at the show/hide events.


          • 2. Re: How do we know when an object is visible?
            Zolotoj Level 3

            How do I override show event in order to add some code to run after the object becomes fully visible?

             

            Thanks

            • 3. Re: How do we know when an object is visible?
              rtalton Level 4

              Create a listener for the show event using ActionScript, or the "show="

              tag in MXML.

              • 4. Re: How do we know when an object is visible?
                Zolotoj Level 3

                So, what exactly show event represents? A fully painted object, or a process of becoming visible?

                • 5. Re: How do we know when an object is visible?
                  rtalton Level 4

                  The show event is triggered when the object becomes fully visible. Look in the docs at the component you are using, and see its event. Also, look at the "showEffect" property if you just want a simple fade in effect or other effect to play when the object becomes visible.

                  • 6. Re: How do we know when an object is visible?
                    Zolotoj Level 3

                    I checked the docs.

                    It says "Dispatched when an object's state changes from invisible to visible", not sure it answers my question.

                    here my code:

                    <?xml version="1.0" encoding="utf-8"?>
                    <s:BorderContainer
                         xmlns:fx="http://ns.adobe.com/mxml/2009" 
                         xmlns:s="library://ns.adobe.com/flex/spark" 
                         xmlns:mx="library://ns.adobe.com/flex/mx"  
                         width="220" height="162" borderWeight="2" creationComplete="init()"
                         color="#000000" visible="false" backgroundColor="#FAF5D9"
                         dropShadowVisible="true" cornerRadius="10">
                         <s:layout>
                              <s:HorizontalLayout horizontalAlign="center" verticalAlign="middle"/>
                         </s:layout>
                         <fx:Script>     
                              <![CDATA[
                                   import mx.core.*;
                                   public var printSticker:Boolean = false;
                                   public var paramObj:Object;
                                   private function init():void
                                   {
                                        addEventListener("show", showHandler);
                                   }
                                   private function showHandler(event:Event):void
                                   {
                                        if (printSticker)
                                        {     
                                             callLater(printStickers);
                                        }     
                                   }     
                                   private function printStickers():void
                                   {
                                        ExternalInterface.call("window.localPrint");
                                   }
                              ]]>
                         </fx:Script>          
                         <s:Label text="{id.substring(7,id.length+1)}" 
                              fontSize="26" textAlign="center" 
                              fontWeight="bold"/>
                    </s:BorderContainer>
                    This code is triggered by setting visible yo true;
                    What's happening is that printing starts before the object is visible on the screen.
                    

                    • 7. Re: How do we know when an object is visible?
                      Flex harUI Adobe Employee

                      Flash is a frame-based display-list renderer.  When you change visible, all

                      you are doing is telling Flash to draw a component when all the other code

                      stops running, including the print dialog.

                       

                      CallLater is sort of the right idea, but in this case it probably just moves

                      the call to the print dialog until after your other code stops running, but

                      still before the player updates the screen.

                       

                      CallLater uses both enterFrame and render events to run code.  If you use

                      callLater in a render event it gets triggered by enterFrame.

                       

                      In cases like this, you either have to use enterFrame or callLater twice.

                      • 8. Re: How do we know when an object is visible?
                        Zolotoj Level 3

                        <callLater twice

                         

                        Like this?

                         

                        callLater(callLater, printStickers)

                        • 9. Re: How do we know when an object is visible?
                          Zolotoj Level 3

                          I tried that. It might be just a tiny bit smoother, but still, the item appears way too late.

                          • 10. Re: How do we know when an object is visible?
                            Flex harUI Adobe Employee

                            Maybe try waiting for updateComplete before calling printStickers.  There

                            might be something going on that takes more than one frame to finish.