首页 \ 问答 \ ActionScript3删除子错误(ActionScript3 remove child error)

ActionScript3删除子错误(ActionScript3 remove child error)

我最近一直在将as2 fla转换为as3(AS3的新功能)并且整个工作都在导出,但是当我尝试在加载新的swf之前删除以前加载的swf时出现错误

ArgumentError: Error #2025: The supplied DisplayObject
must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at MethodInfo-11()

我知道错误与我的removeChild代码有关:

`stage.addEventListener(MouseEvent.CLICK, removeSWF);
function removeSWF (e:MouseEvent):void 
{
if(vBox.numChildren !=0){        
   // swfLoader.unloadAndStop();
    vBox.removeChild(swfLoader);// empty the movieClip memory
}
}`

但是,我似乎无法为此代码找到合适的重写,它将起作用并且没有错误。 这段代码工作正常,所以我不确定是否值得花时间修复此错误,或者只是保留它。 我已经搞砸了几天了,所以在这一点上我无法解决这个问题让我感到沮丧。 在这种情况下,舞台鼠标单击侦听器很有用,因为我在此代码中没有显示后退按钮,在移动到另一个场景之前清除加载的swf。 有没有人看到一个简单的解决方案,或者你认为没有必要追求,因为代码符合我的要求? 完整代码:

function launchSWF(vBox, vFile):void    {
var swfLoader:Loader = new Loader();
var swfURL:URLRequest = new URLRequest(vFile);
swfLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadProdComplete);
swfLoader.load(swfURL);

function loadProdComplete(e:Event):void {
    trace("swf file loaded");   
    vBox.removeChild(preLoader);
    vBox.addChild(swfLoader);   
    currentSWF = MovieClip(swfLoader.content);
    currentSWF.gotoAndPlay(1);
    currentSWF.addEventListener(Event.ENTER_FRAME , checkLastFrame);
    swfLoader.x = 165;
    swfLoader.y = 15;

    function checkLastFrame(e:Event):void { 
        if (currentSWF.currentFrame == currentSWF.totalFrames) {
        currentSWF.stop();
        // trace("DONE");     
        }
    }      
} 
var preLoader:loader = new loader();
preLoader.x = 450;
preLoader.y = 280;
vBox.addChild(preLoader);

        function onProgressHandler(event:ProgressEvent){
            var dataAmountLoaded:Number=event.bytesLoaded/event.bytesTotal*100;
            //preLoader.bar.scaleX = dataAmountLoaded/100;
            preLoader.lpc.text= int(dataAmountLoaded)+"%";
            //trace(preLoader.bar.scaleX );
        }   
//NEW ERRORS BUT WORKING
stage.addEventListener(MouseEvent.CLICK, removeSWF);
function removeSWF (e:MouseEvent):void 
{
if(vBox.numChildren !=0){        
   // swfLoader.unloadAndStop();
    vBox.removeChild(swfLoader);// empty the movieClip memory
}
}
}
var container:MovieClip = new MovieClip();
var currentSWF:MovieClip = new MovieClip();

fall_b.addEventListener(MouseEvent.CLICK, fall_bClick);
  function fall_bClick(e:MouseEvent):void {
  var swfFile:String = 'load/fall.swf';
  launchSWF(container, swfFile);
  addChild(container);
  }

face_b.addEventListener(MouseEvent.CLICK, face_bClick);
  function face_bClick(e:MouseEvent):void {
  var swfFile:String = 'load/face.swf';
  launchSWF(container, swfFile);
  addChild(container);
  }

rott_b.addEventListener(MouseEvent.CLICK, rott_bClick);
  function rott_bClick(e:MouseEvent):void {
  var swfFile:String = 'load/rottgut.swf';
  launchSWF(container, swfFile);
  addChild(container);
  }
//MORE SWFS...

任何人的建议表示赞赏


I recently have been converting an as2 fla to as3 (new to AS3) and have the entire thing working on export, but I am getting an error when I try to remove previously loaded swf's before a new swf is loaded

ArgumentError: Error #2025: The supplied DisplayObject
must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at MethodInfo-11()

I know the error relates to my removeChild code here:

`stage.addEventListener(MouseEvent.CLICK, removeSWF);
function removeSWF (e:MouseEvent):void 
{
if(vBox.numChildren !=0){        
   // swfLoader.unloadAndStop();
    vBox.removeChild(swfLoader);// empty the movieClip memory
}
}`

However, I cannot seem to find a suitable rewrite for this code that will work and not have an error. This code IS working, so I'm not sure if it would be worth my time to fix this error, or just leave it. I've already messed with it for a couple days, so at this point it's just frustrating me that I cannot fix it. The stage mouse click listener is useful in this case because I have a back button not shown in this code that clears the loaded swf's before moving to another scene. Does anyone see a simple solution for this, or do you think it is unnecessary to pursue since the code does what I require? ENTIRE CODE:

function launchSWF(vBox, vFile):void    {
var swfLoader:Loader = new Loader();
var swfURL:URLRequest = new URLRequest(vFile);
swfLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadProdComplete);
swfLoader.load(swfURL);

function loadProdComplete(e:Event):void {
    trace("swf file loaded");   
    vBox.removeChild(preLoader);
    vBox.addChild(swfLoader);   
    currentSWF = MovieClip(swfLoader.content);
    currentSWF.gotoAndPlay(1);
    currentSWF.addEventListener(Event.ENTER_FRAME , checkLastFrame);
    swfLoader.x = 165;
    swfLoader.y = 15;

    function checkLastFrame(e:Event):void { 
        if (currentSWF.currentFrame == currentSWF.totalFrames) {
        currentSWF.stop();
        // trace("DONE");     
        }
    }      
} 
var preLoader:loader = new loader();
preLoader.x = 450;
preLoader.y = 280;
vBox.addChild(preLoader);

        function onProgressHandler(event:ProgressEvent){
            var dataAmountLoaded:Number=event.bytesLoaded/event.bytesTotal*100;
            //preLoader.bar.scaleX = dataAmountLoaded/100;
            preLoader.lpc.text= int(dataAmountLoaded)+"%";
            //trace(preLoader.bar.scaleX );
        }   
//NEW ERRORS BUT WORKING
stage.addEventListener(MouseEvent.CLICK, removeSWF);
function removeSWF (e:MouseEvent):void 
{
if(vBox.numChildren !=0){        
   // swfLoader.unloadAndStop();
    vBox.removeChild(swfLoader);// empty the movieClip memory
}
}
}
var container:MovieClip = new MovieClip();
var currentSWF:MovieClip = new MovieClip();

fall_b.addEventListener(MouseEvent.CLICK, fall_bClick);
  function fall_bClick(e:MouseEvent):void {
  var swfFile:String = 'load/fall.swf';
  launchSWF(container, swfFile);
  addChild(container);
  }

face_b.addEventListener(MouseEvent.CLICK, face_bClick);
  function face_bClick(e:MouseEvent):void {
  var swfFile:String = 'load/face.swf';
  launchSWF(container, swfFile);
  addChild(container);
  }

rott_b.addEventListener(MouseEvent.CLICK, rott_bClick);
  function rott_bClick(e:MouseEvent):void {
  var swfFile:String = 'load/rottgut.swf';
  launchSWF(container, swfFile);
  addChild(container);
  }
//MORE SWFS...

Any advice anyone has is appreciated


原文:https://stackoverflow.com/questions/32258517
更新时间:2022-06-27 19:06

最满意答案

我没有对它进行测试,但是你不能只使用没有先决条件的模式规则,并在单独的行中指定每个目标的先决条件吗?

a.tex: $(wildcard /foo/work1/a.tex)
b.tex: $(wildcard /foo/work2/b.tex)

%.tex:
    cp -p $< $@

顺便说一句。 当没有找到匹配项时,通配符函数不会返回空字符串,因此$<也是空的吗? 这不会给cp带来问题吗?


I ended up doing this:

COPYFILES = /foo/work1/a.tex /foo/work2/b.tex

define copyrule
$(notdir $(1)): $$(wildcard $(1))
    cp -p $$< $$@
endef
$(foreach file,$(COPYFILES),$(eval $(call copyrule,$(file))))

The advantage of this method is that I can easily add new files with a minimum of boilerplate text and I can easily copy the rule part of this to a new Makefile. The disadvantages are that I can no longer change the destination filename, and the implementation is rather opaque for people with less makefile experience.

相关问答

更多
  • 我认为如果您还将控制台的代码页更改为65001(这是一种“UTF-8代码页”),它将起作用。 为此,您必须向批处理文件添加命令: :: Call Of Duty® 2 chcp 65001 xcopy "F:\Archivos de Programa\Call Of Duty® 2\main\players" ^ "D:\BackUp\savegames\Call Of Duty® 2\main\players\" /E /F /Y 有关65001的更多信息,请参阅: 代码页65001和utf-8 ...
  • 假设您有generic/src/foo.cpp和specific.src/bar.cpp 。 这个: $(BIN_DIR)/%.o: %.cpp $(CC) $(CPPFLAGS) $*.cpp -o $@ 非常接近你所需要的(我用自动变量 $@替换了$(BIN_DIR)/$*.o ,它扩展为目标的名称); 唯一的问题是它不起作用。 这个规则告诉Make它可以从foo.cpp构建obj/foo.o ,但是没有foo.cpp 。 有一个generic/src/foo.cpp ,但Make不知道那就是 ...
  • 假设: 你编写非可移植代码,利用非可移植函数[_fullpath() ] 1 您只针对Windows 您使用_fillpath()而不是_wfullpath()禁用unicode 您不想使用第三方库 如何用Windows做到这一点? 您可以使用FindFirstFile()和FindNextFile()来遍历目录。 MSDN有一个很好的例子来说明如何使用它们。 不幸的是, FindFirstFile()非常基本,并且仅限于根据包含通配符的文件名搜索条目。 当你在寻找目录时,它更棘手:你必须使用FindFir ...
  • 我没有对它进行测试,但是你不能只使用没有先决条件的模式规则,并在单独的行中指定每个目标的先决条件吗? a.tex: $(wildcard /foo/work1/a.tex) b.tex: $(wildcard /foo/work2/b.tex) %.tex: cp -p $< $@ 顺便说一句。 当没有找到匹配项时,通配符函数不会返回空字符串,因此$<也是空的吗? 这不会给cp带来问题吗? I ended up doing this: COPYFILES = /foo/work1/a.tex / ...
  • 有可能:为$(SRC:%.c=$(BIN_DIR)/%.o)添加规则。 不建议这样做:这不是常见做法,也不是在bin目录中包含*.o文件的想法。 通常的做法是在同一目录中make读写文件,一旦编译完所有内容,就可以使用单独的install步骤将编译后的软件复制到最终位置,通常称为$(DESTDIR) 。 It is possible: add a rule for $(SRC:%.c=$(BIN_DIR)/%.o). It is not to be recommended: it is not common ...
  • 在build.gradle文件的dependencies部分中,您可以使用FileTree引用。 例如: dependencies { compile fileTree(dir: "${jbossDir}/client", includes: ['*.jar']) } 这将包括JBoss / client目录中的所有JAR文件作为编译时依赖项。 In the dependencies section of your build.gradle file you can use a FileTree ...
  • 您现在使用makefile的问题是您只将代码列为依赖项,而不是数据。 这就是很多魔术发生的地方。 如果“分析”知道它将使用哪些文件并且可以将它们列为依赖项,那么它可以回顾它们是如何制作的以及它们具有哪些依赖关系。 如果管道中的早期文件已更新,那么它可以运行所有必要的步骤以使文件保持最新。 例如 import: rawdata.csv rawdata.csv: scp remoteserver:/rawdata.csv . transform: tansdata.csv transdata.cs ...
  • 你可以试试 task copyRuntimeLibs(type: Copy) { from (configurations.providedCompile){ exclude 'ehcache-2.10.3.jar' } into "build/docker/dependenciesLibrary" } 并且 task copyRuntimeLibs(type: Copy) { from (configurations.providedCompile){ ...
  • 可能不会抛出此错误,但make执行的命令返回非零退出状态,在这种情况下状态为1(由于错误1); 然后顶级make错误2停止。请注意,默认情况下,一旦命令失败, make就会停止。 由于输出没有显示执行了什么命令,因此无法确切地说明出现了什么问题。 编辑 :从GNU制作手册: -d Print debugging information in addition to normal processing. The debugging information says which ...
  • 使用一些文本操作函数 ,您可以首先根据您的目录和FILES列表构建头文件和源文件列表: HDS_FILES = $(addsuffix .h,$(addprefix $(HDS)/,$(FILES))) SRC_FILES = $(addsuffix .cpp,$(addprefix $(SRC)/,$(FILES))) DRV_FILES = $(addsuffix _driver.cpp,$(addprefix $(DRV)/,$(FILES))) 然后,添加没有配方的目标以指定源,驱动程序和头文件之 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)