【发布时间】:2014-02-02 11:37:35
【问题描述】:
我有一个模态窗口,我在打开和关闭时显示调整大小动画,但有时它会在关闭时闪烁。
我已经追踪到一件事。当我在窗口外单击时,关闭动画播放正常。代码在主应用程序中,在mouseUpOutsideHandler 方法中。这是对PopUpManager.removePopUp() 的简单调用。当我单击窗口内的关闭按钮时,它在窗口内的close() 方法中运行相同的代码PopUpManager.removePopUp(),但它首先闪烁。
除了从模态窗口实例中调用之外,它的代码完全相同。看起来模态窗口正在淡出然后被删除,然后播放我的删除动画。请参阅代码示例。
示例:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import com.flexcapacitor.effects.popup.OpenPopUp;
import mx.core.IFlexDisplayObject;
import mx.managers.PopUpManager;
protected function showPopUp():void {
var myPopUp:MyPopUp = new MyPopUp();
PopUpManager.addPopUp(myPopUp as IFlexDisplayObject, this, true);
PopUpManager.centerPopUp(myPopUp);
myPopUp.addEventListener(OpenPopUp.MOUSE_DOWN_OUTSIDE, mouseUpOutsideHandler, false, 0, true);
}
private function mouseUpOutsideHandler(event:Event):void {
// does not create a flicker
PopUpManager.removePopUp(event.currentTarget as IFlexDisplayObject);
MyPopUp(event.currentTarget).removeEventListener(OpenPopUp.MOUSE_DOWN_OUTSIDE, mouseUpOutsideHandler);
}
]]>
</fx:Script>
<fx:Declarations>
<fx:Component className="MyPopUp">
<s:Panel xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
resizeEffect="Resize"
resize="panel1_resizeHandler(event)"
creationCompleteEffect="{addedEffect}"
removedEffect="{removedEffect}"
width="400" height="200">
<fx:Script>
<![CDATA[
import mx.events.ResizeEvent;
import mx.managers.PopUpManager;
protected function close():void {
// when called here creates a flicker effect
// it looks like the pop up is faded out and removed
// and then the removed effect is played
PopUpManager.removePopUp(this);
}
protected function panel1_resizeHandler(event:ResizeEvent):void {
if (stage && !addedEffect.isPlaying) {
PopUpManager.centerPopUp(this);
}
}
]]>
</fx:Script>
<fx:Declarations>
<s:Parallel id="removedEffect" target="{this}" >
<s:Scale3D scaleYTo="0" duration="1000" startDelay="0" disableLayout="false"
autoCenterProjection="true" autoCenterTransform="true"/>
<s:Fade alphaFrom="1" alphaTo="0" duration="500" startDelay="50"/>
</s:Parallel>
<s:Parallel id="addedEffect" target="{this}" >
<s:Scale3D scaleYFrom="0" scaleYTo="1" duration="250" disableLayout="false"
autoCenterProjection="true" autoCenterTransform="true"/>
<s:Fade alphaFrom="0" alphaTo="1" duration="200"/>
</s:Parallel>
</fx:Declarations>
<s:Label horizontalCenter="0" verticalCenter="0" text="Hello World"/>
<s:Button horizontalCenter="0" verticalCenter="30" label="Close" click="close()"/>
</s:Panel>
</fx:Component>
</fx:Declarations>
<s:Button label="Show Pop Up"
horizontalCenter="0" verticalCenter="0"
click="showPopUp()"
/>
【问题讨论】:
-
如何手动调用隐藏/删除效果并监听 Complete 事件。然后在完整的处理程序中删除弹出窗口。