2 Replies Latest reply on Mar 27, 2008 6:19 AM by SpinGrrl

    Effect working intermittently

    SpinGrrl
      Hello All,

      I am working on building a custom layout functionality into my applicaton. So far, I have been able to load several different windows (popup windows) and then save the current layout and then save it to a list to be loaded at any time. I wanted to add some nice effects. Basically, if the windows in the saved layout are already open, the application will move and resize the windows to the saved x,y, width, & height in an animated fashion. Looks really nice and works fine. Now, I have another effect that if a window is not currently visible or open it will use a fadeIn effect. It will fade from an alpha of 0 to 1. All of my windows are managed by the PopupManager so even when you close one of the windows, it's really only being set visible=false. The problem I'm having is the fadeIn effect will work sometimes, and other times it will not. Sometimes the window will load, but be invisible. This functionality has been added to a custom component that all of my windows extend. You can imagine this is very frustrating. Below is a snippet of my code. Please feel free to post any direction - it would be greatly appreciated:



      public function handleOpen():void{
      if(this.is_init == false){
      PopUpManager.addPopUp(this,mx.core.Application.application.MainWindow,modal);
      this.is_init = true;
      }

      if(!this.visible){
      this.initWindow();
      this.playWindowAppear();

      //We don't want the saveLayoutForm popup to be considered an active window for saving.
      if (this._mainmenu_data != "saveLayoutForm"){
      mx.core.Application.application.MainMenu.addActiveWindow(this);
      }
      } else {
      //if the window is visible, we want it to use the move effect
      if(this._explicitSize){
      this.playWindowMove();
      }
      }
      PopUpManager.bringToFront(this);
      }


      /*************************************************************************
      *********************** SPECIAL EFFECTS ********************************
      *************************************************************************/

      /** Function to add an effect to fade windows into view. **/
      public function playWindowAppear():void {
      var effectSequence:Sequence = new Sequence();

      /** Pause Effect ** used to scatter the special effects **/
      var pause:Pause = new Pause(this);
      pause.duration = this._effectStart;
      effectSequence.addChild(pause);

      /** Fade Effect ** Fades the window slowly from invisible to visible **/
      var fadeIn:Fade = new Fade(this);
      fadeIn.duration = 100;
      fadeIn.alphaFrom = 0;
      fadeIn.alphaTo = 1;
      effectSequence.addChild(fadeIn);

      // If the _effectStart is a negative number we are intentionally trying to skip this effect.
      if(this._effectStart >= 0){
      /** Play the effect **/
      this.alpha = 0;
      this.visible = true;
      if(effectSequence.isPlaying){
      effectSequence.end();
      }
      effectSequence.play();
      /**if(this.alpha < 1){
      this.alpha = 1;
      }**/

      }else{
      this.visible = true;
      }
      }

      /**
      * This function will move and resize windows smoothly on the screens
      */
      public function playWindowMove():void {
      var effectSequence:Sequence = new Sequence();

      /** Pause Effect ** used to scatter the special effects **/
      var pause:Pause = new Pause(this);
      pause.duration = this._effectStart;
      effectSequence.addChild(pause);

      /** Move the window on its X axis **/
      var moveX:Move = new Move(this);
      moveX.xFrom = this.x;
      moveX.xTo = this._openX;
      //if there will be no movement, then we want the duration to be 0
      if(this.x-this._openX != 0){
      moveX.duration = 100;
      }else
      moveX.duration = 0;
      effectSequence.addChild(moveX);

      /** Move the window on its Y axis **/
      var moveY:Move = new Move(this);
      moveY.yFrom = this.y;
      moveY.yTo = this._openY;
      //If there will be no movement, then we want the duration to be 0
      if(this.y-this._openY != 0){
      moveY.duration = 100;
      }else{
      moveY.duration = 0;
      }
      effectSequence.addChild(moveY);

      /** Resize the window **/
      var resize:Resize = new Resize(this);
      resize.widthFrom = this.width;
      resize.widthTo = this._openWidth;
      resize.heightFrom = this.height;
      resize.heightTo = this._openHeight;
      //If the window will not be resized, then we want the duration to be 0
      if(this.width-this._openWidth != 0 && this.height-this._openHeight != 0){
      resize.duration = 100;
      }else{
      resize.duration = 0;
      }
      effectSequence.addChild(resize);

      /** Play the effect **/
      effectSequence.play();
      }
        • 1. Re: Effect working intermittently
          cxf02 Level 1
          I can't comment on this fully because i need to get some sleep. However, my experience with events and popups for any application in windows is to watch out for events that can get "lost" (events are asynchronous) because they have been interrupted by focus. In the case of modal windows, this problem can cause weird effects.

          If you continue to experience this issue, try using the same effects on objects that do not popup. Personally, i wouldn't use a popup to save my life unless it was a wizard, and even then I would try to do it another way, like use a viewstack or states. If your code works without the popups then there is probably an event timing issue. The real problem is that the PLAYER is captive to the operating system when it comes to handling events, even though PLAYERS are virtual machines they have to operate by the OS rules. My point is, if it is an asynchronous issue, you may be able to fix this with some timers or some other technique on your machine, but will it play the same on another OS? How about a slower CPU machine?

          Give it some thought and run it through your debugger over and over. Also, capture events and trace them in your windows by temporarily overriding the dispatchevent in them like so...

          override public function dispatchEvent(event:Event):Boolean {
          trace(event); // get the event info out in multiple trace statements
          return super.dispatchEvent(event);
          }

          email me at curtis dot fisher at procontent dot net if you want some more assistance. sounds like an interesting problem.

          • 2. Re: Effect working intermittently
            SpinGrrl Level 1
            Curtis,

            Thank you for the response. It makes a lot of sense, I will add some extra debugging to see if I can figure out where it's not working. I thought about changing to transitions, but it uses the same stuff, just a different way of defining it so I'm worried that I would still run into problems.

            -Amanda