• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Games Fantasy
博客园    首页    新随笔    联系   管理    订阅  订阅
flex的stage[转]

首先注意一下.
这里说的是在"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>

 

我们在creationComplete事件里,使用callLater(init)来调用init,让init在进入下一侦的时候再全屏..
保存运行swf,问题解决....

ps:另外swf还可以使用fscommand("fullscreen", "true");来进行全屏..这里只是主要讨论stage为null的问题.

posted on 2010-03-13 10:52  ╰洛つ☆泺oO  阅读(3006)  评论(1)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3