【发布时间】:2011-05-03 15:21:18
【问题描述】:
我正在尝试创建一个具有平滑过渡效果的扩展表单,代码如下:
<s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
currentState="Login" creationPolicy="all"
close="PopUpManager.removePopUp(this)">
<fx:Metadata>
[ResourceBundle("I18N")]
</fx:Metadata>
<s:states>
<s:State name="Login" ></s:State>
<s:State name="Register"></s:State>
</s:states>
<fx:Script>
<![CDATA[
import caurina.transitions.Tweener;
import mx.controls.Alert;
import mx.managers.PopUpManager;
[Bindable]private var show:Boolean = false;
private function extendForm():void
{
Tweener.addTween(this, {height:320, time:1, onComplete:this.toogleMode(true)})
}
private function reduceForm():void
{
Tweener.addTween(this, {height:150, time:1, onComplete:this.toogleMode(false)});
}
private function toogleMode(visible:Boolean):void
{
this.show = visible;
if(visible){this.setCurrentState("Register");}
else{this.setCurrentState("Login")}
}
]]>
</fx:Script>
<fx:Declarations>
<mx:EmailValidator source="{email}" property="text" required="true"
trigger="{submit}" triggerEvent="click"
valid="Alert.show('Validation Succeeded!');"/>
<mx:Validator source="{password}" property="text" required="true"
trigger="{submit}" triggerEvent="click"
requiredFieldError="{resourceManager.getString('I18N','requiredField')}"/>
<mx:Validator source="{repeatpw}" property="text"
trigger="{submit}" triggerEvent="click"
required="{show}" requiredFieldError="{resourceManager.getString('I18N','requiredField')}"/>
</fx:Declarations>
<s:VGroup id="container" width="100%" height="100%" gap="10">
<s:Group width="100%" height="100%">
<mx:Form id="formfield" width="100%" height="100%" left="0" layoutDirection="ltr" creationPolicy="all" >
<mx:FormItem creationPolicy="all" label="{resourceManager.getString('I18N','email')}">
<s:TextInput id="email"
width="100%"
maxChars="40"
minWidth="170" />
</mx:FormItem>
<mx:FormItem creationPolicy="all" label="{resourceManager.getString('I18N','password')}">
<mx:TextInput id="password"
width="100%"
displayAsPassword="true"
maxChars="40"
minWidth="170"/>
</mx:FormItem>
<mx:FormItem creationPolicy="all" includeIn="Register" label="{resourceManager.getString('I18N','repeatpw')}">
<s:TextInput id="repeatpw"
width="100%"
displayAsPassword="true"
maxChars="40"
minWidth="170" />
</mx:FormItem>
</mx:Form>
</s:Group>
<s:HGroup width="100%">
<s:Group>
<s:Button includeIn="Login" enabled="{!show}" label="{resourceManager.getString('I18N','register')}" left="5" bottom="5" click="{this.extendForm()}"/>
<s:Button includeIn="Register" enabled="{show}" label="{resourceManager.getString('I18N','login')}" left="5" bottom="5" click="{this.reduceForm()}"/>
</s:Group>
<mx:Spacer width="100%" height="100%"/>
<s:HGroup>
<s:Button label="{resourceManager.getString('I18N','submit')}" id="submit"/>
<s:Button label="{resourceManager.getString('I18N','cancel')}" click="PopUpManager.removePopUp(this)" />
</s:HGroup>
</s:HGroup>
</s:VGroup>
但问题在于,即使将 creationPolicy 设置为 all,并非所有项目似乎都已初始化。这会导致第一次单击“注册”按钮时补间动画滞后。第一次点击后,动画流畅。
谁能告诉我我做错了什么或者是什么导致动画滞后?
【问题讨论】:
标签: flash apache-flex actionscript-3 flex4