Show/hide if not applied already

Posted by krumedia 
Show/hide if not applied already
February 09, 2011 08:50PM
Hello,

calling hide() on a hidden element will repeat the hide transition. How do i achieve the transition is only played once?

This is what i tried: (my try was to add a helper method to a derived class of FlashEff2Flex)

		public function toVisibility(visible:Boolean):void
		{
			if (this.isTransitioning)
			{
				var toTransitionType:String = visible ? "show" : "hide";
				if (this.currentTransitionType == toTransitionType)
				{
					return;
				}
				
				this.stop();
			}
			else if (target.visible == visible) // won't work!
			{
				return;
			}
			
			if (visible) this.show();
			else this.hide();
		}

So frustrating: Closed source is such a pain like walking with tied hands.
Re: Show/hide if not applied already
February 10, 2011 06:43AM
Sorry, but could you please tell me specifically what you want to obtain?Thank you.
Re: Show/hide if not applied already
February 10, 2011 02:15PM
Hi kneo,

i would like to set the visibility of an element to visible or hidden.
FlashEff should only start the animation if the target's visibility is different from the "new" visibility and if the right transition is not currently playing.

Thanks, Matthias
Re: Show/hide if not applied already
February 10, 2011 03:22PM
Why don't you just do this:

if (effect.currentTransitionType == "hide") {
effect.show();
}else{
effect.hide();
}
or

if (effect.currentTransitionType == "hide") {
visibility=false
}else{
visibility=true
}.........
Re: Show/hide if not applied already
February 10, 2011 04:31PM
Hi kneo,

this is the original setter:

		public function set showDescription(value:Boolean):void
		{
			descriptionArea.visible = value;
		}


To enable FlashEff my first approach is:

		public function set showDescription(value:Boolean):void
		{
			if (value) effect.show();
			else effect.hide();
		}

But there is a problem: If the target's visibility equals value (the setter argument) no animation should be played.
There are two cases the animation should not play:
- initial calls to show()/hide() result in the same visibility:
		<fx:Script>
			private function test():void
			{
				effect.hide(); // call to hide() should do nothing since myControl.visible == false already
			}
		</fx:Script>
		<my:Control id="myControl" visible="false" />
- show()/hide() has been called and a second call of show()/hide() is made
		<fx:Script>
			private function method1():void
			{
				effect.hide(); // will hide myControl
			}
			private function method2CalledLater():void
			{
				effect.hide(); // should not play the hide transition again
			}
		</fx:Script>
		<my:Control id="myControl" />
Re: Show/hide if not applied already
February 11, 2011 11:26AM
Try to use this code.
package
{
	public class MyFlashEff extends FlashEff2Flex
	{
		public function MyFlashEff()
		{
			super();
		}
		protected var visibility:Boolean = false;
		
		override public function show(arg0:*=null):void{
			super.show(arg0);
			visibility=true
		}

		override public function hide():void{
			
			super.hide();
			visibility = false;
		}
		public function toVisibility(visible:Boolean):void
			{
				
				if (this.isTransitioning)
				{
					var toTransitionType:String = visible ? "show" : "hide";
					if (this.currentTransitionType == toTransitionType)
					{
						return;
					}
					
					
				}
				else if (visibility == visible) // won't work!
				{
					return;
				}
			
				if (visible) this.show();
				else this.hide();
			}
		
	}
}

The method that you used works only if you have a movieclip as a target and not a textfield.
Re: Show/hide if not applied already
February 24, 2011 11:33AM
This is the final version that will work:


public class MyFlashEff extends FlashEff2Flex 
{
	
	protected var endingVisibility:Boolean = false;

	
	public function MyFlashEff() 
	{
		super();
		
		this.includeInLayout = false;
		this.visible = false;
		this.showAutoPlay = false;
		this.hideAutoPlay = false;
		
		addEventListener(FLASHEFFEvents.TRANSITION_START, effectStarting);
		addEventListener(FLASHEFFEvents.TRANSITION_END, effectEnding);
	}
	
	override public function set target(value:DisplayObject):void 
	{
		this.endingVisibility = value != null && value.visible;
		super.target = value;
	}
	
	override public function show(arg0:* = null):void 
	{
		this.endingVisibility = true;
		super.show(arg0);
	}
	
	override public function hide():void 
	{
		this.endingVisibility = false;
		super.hide();
	}
	
	public function toVisibility(visible:Boolean):void
	{
		if (visible != this.endingVisibility)
		{
			if (visible) this.show();
			else this.hide();
		}
	}
	
	private function effectStarting(e:FLASHEFFEvents):void 
	{
		this.visible = true;
	}
	
	private function effectEnding(e:FLASHEFFEvents):void 
	{
		if (currentTransitionType == "hide")
		{
			this.visible = false;
		}
	}
	
}
Sorry, you do not have permission to post/reply in this forum.