首先注意一下.
这里说的是在"FLEX"生成的"SWF"直接运行时,使用"stage.displayState"启用全屏时所遇到的问题...

注意上面""号所提到的关健词..

现在我们先看看代码,下面的代码装在creationComplete事件中调用init()来启动全屏.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
	layout="absolute"
	creationComplete="init()"
	>
	<mx:Script>
		<![CDATA[
			private function init():void{
				stage.displayState = StageDisplayState.FULL_SCREEN; 
			}
		]]>
	</mx:Script>
</mx:Application>

 

现在保存运行一下swf,却有TypeError..详细信息如下

Main Thread (Suspended: TypeError: Error #1009: 无法访问空对象引用的属性或方法。)  
	swf_fullscreen/init  
	swf_fullscreen/___swf_fullscreen_Application1_creationComplete  
	flash.events::EventDispatcher/dispatchEventFunction [no source]  
	flash.events::EventDispatcher/dispatchEvent [no source]  
	mx.core::UIComponent/dispatchEvent  
	mx.core::UIComponent/set initialized  
	mx.managers::LayoutManager/doPhasedInstantiation  
	Function/http://adobe.com/AS3/2006/builtin::apply [no source]  
	mx.core::UIComponent/callLaterDispatcher2  
	mx.core::UIComponent/callLaterDispatcher  

 

我们把init()修改一下,如下

private function init():void{
	trace(stage)
}

 

运行保存运行swf,发现输入null,奇怪的事情发生了..stage竟然为null,那进行stage.displayState当然就报错了...
再次修改程序,使用click调用init(),stage正常输出,那问题大概就是creationComplete调用时,stage初始化..

后来网上查了一下..发现了一个叫callLater的函数,他的功能大概是..进入下一帧的时候,执行函数,我们再次修改代码:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout
="absolute"
creationComplete
="callLater(init)"
>
<mx:Script>
<![CDATA[
private function init():void{
stage.displayState = StageDisplayState.FULL_SCREEN;
}
]]>
</mx:Script>
</mx:Application>

相关文章:

  • 2022-01-14
  • 2021-08-31
  • 2022-02-14
  • 2021-12-20
猜你喜欢
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-27
  • 2022-12-23
  • 2021-11-25
  • 2022-12-23
相关资源
相似解决方案