将组件添加到 Swf 库的正确方法是什么?
在开发Flash项目的过程中,一直有一个问题多次困扰着我。它看起来像这样:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at fl.containers::BaseScrollPane/fl.containers:BaseScrollPane::drawBackground()
at fl.controls::TileList/fl.controls:TileList::draw()
at fl.core::UIComponent/::callLaterDispatcher()
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChildAt()
at fl.controls::BaseButton/fl.controls:BaseButton::drawBackground()
at fl.controls::BaseButton/fl.controls:BaseButton::draw()
at fl.core::UIComponent/drawNow()
at fl.controls::ScrollBar/fl.controls:ScrollBar::draw()
at fl.core::UIComponent/::callLaterDispatcher()
现在,就我而言,此错误源于代码中的初始化组件,而这些组件尚未显式添加到 CS4 中的 fla 组件库中。过去,我在尝试在代码中动态创建 ScrollPanes 时遇到过这个问题。我通过将 ScrollPane 组件添加到 Main.fla 的库中解决了这个问题。这似乎有效了一段时间。
现在,我正在尝试使用 AstraFlash AutoComplete 框。我已将正确的 fla 文件导入到 CS4 中,并将自动完成框放入我的 Swf 中。一切构建正常,但加载 Swf 时会出现上述错误。我的想法是,自动完成框正在尝试创建 ScrollPane 作为其功能的一部分。好的,我明白了这一点,所以我也将 ScrollPane 组件添加到库中,并得到相同的结果。
通常我只会弄乱库组件/设置,直到消除错误为止,但我厌倦了遇到这种情况,并且我想知道解决问题的正确方法。因此,我有几个问题:
什么时候需要将组件添加到 Fla 的库,而不是仅仅在代码中创建组件?
您需要将组件添加到哪个 Flas 中?就只有那个人在用吗?或者是佛罗里达州所有的父母?
假设 Autocomplete 组件需要 ScrollPane 组件。为什么当我添加一个组件时无法识别这种依赖关系?为什么我必须显式添加它?
将组件添加到库中与将其添加到库的“组件资源”文件夹中有何区别?该文件夹的用途是什么?
我真的需要这个自动完成组件才能工作。假设 AS3 代码是正确的,但我仍然收到上述错误,您认为哪些设置可能不正确?出于沮丧,我尝试将所有可能的组件添加到库中,以及库的组件资产文件夹中,只是为了有一个起点,但我仍然收到错误。
任何帮助表示赞赏。
I've been having a problem that's plagued me many times in the course of developing a Flash project. It looks something like this:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at fl.containers::BaseScrollPane/fl.containers:BaseScrollPane::drawBackground()
at fl.controls::TileList/fl.controls:TileList::draw()
at fl.core::UIComponent/::callLaterDispatcher()
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChildAt()
at fl.controls::BaseButton/fl.controls:BaseButton::drawBackground()
at fl.controls::BaseButton/fl.controls:BaseButton::draw()
at fl.core::UIComponent/drawNow()
at fl.controls::ScrollBar/fl.controls:ScrollBar::draw()
at fl.core::UIComponent/::callLaterDispatcher()
Now, in my case, this error stems from initializing components in code when they have not been explicitly added to the fla's component library in CS4. In the past, I have run into this issue when trying to dynamically create ScrollPanes in code. I have solved it by adding ScrollPane components to my Main.fla's library. This seemed to work for a while.
Now, I am trying to use an AstraFlash AutoComplete box. I have imported the proper fla files into CS4, and placed an AutoComplete box into my Swf. Everything builds fine, but the above error occurs when the Swf is loaded. My thought is that the AutoComplete box is trying to create a ScrollPane as part of its functionality. Ok, I understand this, so I add the ScrollPane component to the library as well with the same results.
Usually I would just mess with the library components/settings until I get rid of the error, but I'm sick of running into this, and I want to know the correct way to solve the problem. So, here are a few questions I have:
When are you required to add a component to a Fla's library rather than just creating the component in code?
Which Flas do you need to add the component to? Just the one using it? Or all of parents of that Fla as well?
Let's say the Autocomplete component requires a ScrollPane component. Why isn't this dependency recognized when I add the one component? Why must I explicitly add it?
What is the difference between adding a component to the library, and adding it to the library's 'Component Assets' folder? What is this folder's purpose?
I really need this AutoComplete component to work. Assuming the AS3 code is correct, and I am still getting the above error, what settings do you think are probably incorrect? Out of frustration, I have tried adding every possible component to the library, as well as to the library's component assets folder just to have a starting point, but I still get the error.
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定我是否理解你的设置。我假设你有一个包含一些组件的子 fla,并且你需要在父(加载器)fla 中创建这些组件的实例。
如果您将子 fla 中的类编译到父 fla 中,它应该可以工作,但这会重复一些事情。
问题是当您加载 swf 时,这些类位于不同的 应用程序域。
简而言之,它是管理 swf 中的类的东西,因此加载器和加载的 swf 以及其他一些安全内容之间不会发生类冲突。
我制作了一个简单的 fla,其中包含一个 Button 组件(fl.controls.Button)并从加载器 fla 加载它。我没有将 Button 组件添加到加载器 fla 中,但使用加载的 swf 的应用程序域创建了一个按钮实例。方法如下:
《Programming Actionscript 3.0》中有一个页面介绍了此类问题以及如何使用 ApplicationDomain,但说实话我并没有完全理解它。
哈特哈,
乔治
I'm not sure I understand you're setup. What I'm assuming is you have a child fla that contains some components and you need to create instances of those components in a parent(loader) fla.
It should work if you compile the classes from the child fla into the parent fla, but that would duplicate things.
The issue is when you load a swf, the classes sit in a different ApplicationDomain.
Simply put, that's the thing that manages classes in a swf so you don't have class collisions between a loader and loaded swf and some other security stuff.
I made a simple fla that holds a Button component(fl.controls.Button) and loaded that from a loader fla. I didn't add the Button component to the loader fla, but did create a button instance, using the loaded swf's application domain. Here's how:
There is a page in Programming Actionscript 3.0 about thise kind of issues and how to use ApplicationDomain, but I didn't fully understand it to be honest.
HTH,
George