Bug:Flex自动帧频1000!

Jack 撰写  

用Flex4才发现了这个问题,

当用spark添加一个mx组件时不会有问题,但当这个mx组件中还有其他组件

例如<mx:HBox><mx:Canvas/></mx:HBox>

stage.frameRate会瞬间达到1000!

之后会自动恢复到默认的帧频(如果不手动设定,会是24)

这时不用担心什么问题,

但如果frameRate达到1000的这段时间中,添加了一个EnterFrame事件,

并且在EnterFrame的响应函数中,调整某个组件的位置,

frameRate就不会恢复回24,而是一直持续1000,知道取消了EnterFrame为止

源文件:
src
源码如下:
Application.mxml:

<?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" frameRate="12"
			 backgroundColor="0xFF00FF">
	<fx:Script>
		<![CDATA[

			import components.MyComponent;

			import mx.containers.HBox;
			import mx.core.UIComponent;
			import mx.events.FlexEvent;

			protected function button2_clickHandler(event:MouseEvent):void
			{
				trace(this.stage.frameRate);
				this.txt.text = "Current FrameRate:"+this.stage.frameRate.toString();
			}

			protected var _box:UIComponent;
			protected function button3_clickHandler(event:MouseEvent):void
			{
				_box = new MyComponent();
				this.container2.removeAllElements();
				this.container2.addElement(_box);
				button2_clickHandler(null);
				button4_clickHandler(null);
			}

			protected function enterFrameHandler(event:Event):void
			{
				if(_box){
					container1.x+=0.2;
				}
			}
			protected function button4_clickHandler(event:MouseEvent):void
			{
//				this.moveEffect.play([this.container2]);
				this.addEventListener(Event.ENTER_FRAME,this.enterFrameHandler);
			}
			protected function button5_clickHandler(event:MouseEvent):void
			{
				this.removeEventListener(Event.ENTER_FRAME,this.enterFrameHandler);
			}

		]]>
	</fx:Script>

	<fx:Declarations>
		<s:Move id="moveEffect" duration="10000" xFrom="10" xTo="300" yFrom="10" yTo="300"/>
	</fx:Declarations>
	<mx:Canvas id="container1" y="60" width="100%" height="100%"/>
	<s:SkinnableContainer id="container2" x="20" y="80" width="900" height="600"/>

	<s:Group>
		<s:layout>
			<s:HorizontalLayout>
			</s:HorizontalLayout>
		</s:layout>
		<s:Button click="button2_clickHandler(event)" label="Trace frameRate"/>
		<s:Label text="" id="txt" width="100"/>
		<s:Button click="button3_clickHandler(event)" label="load MyComponent"/>
		<s:Button click="button4_clickHandler(event)" label="Start Move"/>
		<s:Button click="button5_clickHandler(event)" label="Stop Move"/>
	</s:Group>
</s:Application>

components/MyComponent.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:fx="http://ns.adobe.com/mxml/2009"
		 xmlns:s="library://ns.adobe.com/flex/spark"
		 xmlns:mx="library://ns.adobe.com/flex/mx"
		 >
	<mx:Canvas backgroundAlpha="1" width="30" height="30" backgroundColor="0x0000F0"/>
</mx:HBox>

发表评论

你必须在 登录 后才能发表评论.