下面是我的代码,问题在它之后得到了解释。
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:cal="cal.*"
layout="absolute"
applicationComplete="init()"
xmlns:geometry="com.degrafa.geometry.*"
xmlns:degrafa="com.degrafa.*"
xmlns:paint="com.degrafa.paint.*"
xmlns:containers="flexlib.containers.*"
xmlns:flexlib_controls="flexlib.controls.*"
xmlns:mdi_containers="flexlib.mdi.containers.*"
xmlns:auto="com.hillelcoren.components.*"
xmlns:local="*"
xmlns:components="CollapsibleAccordion.*"
modalTransparency="0.8"
modalTransparencyColor="0x000000"
backgroundSize="100%">
<mx:Script>
<![CDATA[
import c7.views.components.PhotoViewer.PhotoViewer;
import c7.config.ServerConfig;
import mx.core.Application;
import mx.containers.*;
import c7.models.GlobalModel;
private var pv_slideshow:PhotoViewer = null;
private function toggleFullScreen():void
{
if(stage.displayState == StageDisplayState.NORMAL)
{
this.pv_slideshow = new PhotoViewer;
Application.application.addChild(this.pv_slideshow); //added as top-most component to application itself
//set new sizes & go full-screen
this.pv_slideshow.x = 0;
this.pv_slideshow.y = 0;
this.pv_slideshow.width = stage.fullScreenWidth;
this.pv_slideshow.height = stage.fullScreenHeight;
try
{
stage.displayState = StageDisplayState.FULL_SCREEN;
}
catch(err:Error)
{
Alert.show(err.toString());
}
stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullScreenEventHandler, false, 0, true); //intentionally weak referenced
//refresh the display sizes & display list
invalidateSize();
invalidateDisplayList();
}
/*else
stage.displayState = StageDisplayState.NORMAL;*/
}
private function fullScreenEventHandler(event:FullScreenEvent):void
{
if (event.fullScreen) //nothing to do in case when switching to full-screen
return;
//Alert.show(pv_slideshow.width.toString());
//application.removeChild(this.pv_slideshow);
Application.application.removeChild(pv_slideshow); //remove the full-screen container
this.pv_slideshow = null; //reset
//refresh the display sizes & display list
invalidateSize();
invalidateDisplayList();
}
按一下按钮就会触发toggleFullScreen ...而且它工作得非常好。但问题出在“退出”上。当我单击退出键时,fullScreenEventHandler被触发,它应该删除pv_slideshow。
这就是我在下面的代码行中得到一个空对象引用错误的地方:
Application.application.removeChild(pv_slideshow); //remove the full-screen container我尝试过使用this.pv_slideshow和其他类似的东西。
请帮我弄清楚。我做错了什么,我应该如何让它工作。
这是我得到的确切的错误消息:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::removingChild()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\Container.as:3315]
at mx.core::Container/removeChild()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\Container.as:2263]
at index_cloud/fullScreenEventHandler()[C:\development\flex_src\index_cloud.mxml:1661]发布于 2011-06-05 21:54:48
我也不会使用Application.application。
请先检查pv_slideshow是否真的存在,您可以获取它的父级(如果有),并在以后删除它。
获取父级
pv_slideshow.parent将其从parent_item中删除
parent_item.removeChild( pv_slideshow )还要确保您正在使用的Flex版本,您可能需要使用removeElement.将其删除
发布于 2010-03-12 00:24:01
Application.application的预期架构用途不是将其用作uiComponent或displayObject或其他什么。如果您正在构建一个基于应用程序属性或应用程序的systemManager执行一些计算的库项目,或者您需要从加载的模块访问outter应用程序,那么您有充分的理由使用App.app。
你的例子不是其中的一个例子。你最好的办法就是把你的组件添加到'this‘中(只要你不打算使用一个“视图”容器),然后做一个this.removeChild。这应该会很好地解决你的问题。
祝你好运,杰里米
https://stackoverflow.com/questions/2422167
复制相似问题