Flash/AS3 安全 - 将影片剪辑引用传递给子 swf?
我发现预加载器和主应用程序类(所有 AS3 / Flash CS4)之间的交互存在一些奇怪的行为。粗略地说,事件流程如下:
- Preloader.swf 加载两个内容:main.swf(主应用程序)和由文本和图像组成的自定义对象的资源,这些资源由预加载器从各种 URL 组装到对象中。
- 加载完成后,预加载器将 main.swf 添加为子项。然后,预加载器在 main.swf 上调用
init(myCustomObject)
,其中 myCustomObject 是对预加载器在步骤 1 和public function init(customObject:CustomObject):void) 中组装的对象的引用/pre> 是 Main.as 中的方法签名。 (Preload.as 将 Main 转换为 * 类型的对象,以便能够调用任意函数,而不必担心编译时错误。)
- Main.as 实际上是应用程序本身的容器,因此它实例化一个
new Application(customObject);
传递对预加载器组装的 customObject 的引用,并将其添加为子项。
我已经安装了 thunderbolt 这样我就可以在应用程序运行时记录消息,这就是我确定正在发生的情况。第 3 步中应用程序对象的实例化是造成问题的原因;由于某种原因,该声明 Main.as 中的 myMainApplication = new Application(customobj);
抛出一个可爱的 #1009
错误,该错误通常表示空指针引用或类似的内容。
奇怪的是,我已经向 Application.as
添加了一些日志记录,并且它似乎毫无问题地接收了对 customObject
的引用;在 Application
的构造函数中对 customObject
调用 toString()
会准确返回预期的数据。
换句话说,Main.as 中的语句 myMainApplication = new Application(customobj);
似乎同时成功和失败。什么给?
I'm seeing some strange behavior with respect to interactions between my preloader and main application classes (all AS3 / Flash CS4). Roughly speaking, here's the flow of events:
- Preloader.swf loads two things: main.swf, which is the main app, and assets for a custom object consisting of text and images, which are assembled into the object by the preloader from various URLs.
- When load finishes, Preloader adds main.swf as a child. Preloader then calls
init(myCustomObject)
on main.swf, where myCustomObject is a reference to the object assembled by the preloader during step 1 and
public function init(customObject:CustomObject):void)
is a method signature in Main.as. (Preload.as casts Main to an object of type * so as to be able to invoke arbitrary functions without fear of compile-time errors.)
- Main.as is actually a container for the application itself, so it instantiates a
new Application(customObject);
passing along a reference to the customObject assembled by the preloader, and adds that as a child.
I've installed thunderbolt so I can log messages as the application runs, and here's what I've determined is happening. The instantiation of the Application object in step 3 is what's causing trouble; for some reason, the statementmyMainApplication = new Application(customobj);
in Main.as is throwing a lovely #1009
error, which usually indicates a null pointer reference or something similar.
The strange thing is that I've added some logging to Application.as
, and it seems to be receiving the reference to customObject
without a problem; calling toString()
on the customObject
in Application
's constructor returns exactly the expected data.
In other words, the statement myMainApplication = new Application(customobj);
in Main.as seems to be succeeding and failing at the same time. What gives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我的猜测是,您的转换跨应用程序域,因此尽管类型是相同的文件,但在每个应用程序域的内存中,它们是 2 个独立的具体类型。有很多方法可以解决这个问题,可能从加载到同级应用程序域而不是子域开始,或者不费心进行强制转换并在非类型化对象上显式调用相关函数。
WeLoveAppDomain 如果确实是这个问题,应该会有所帮助。你能举出一个尽可能最小的例子来证明这个失败,以便我们解构吗?
My guess is that your casting accross application domains, so although the types are the same files, in the memory of each application domain they are 2 separate concrete types. There are many ways to get around this, possibly starting with loading into a sibling application domain instead of a child domain, or not bothering with the cast and explicitly calling the function in question on the untyped object.
WeLoveAppDomain should be of some assistance if it is in fact this issue. Can you put together the smallest possible example to demonstrate this failure for us to de-construct?
确保 Flash Player 中的全局安全设置允许对该目录进行本地访问。
试试这个。进入发布设置-本地播放安全-选择“仅访问网络”。 Flash CS4 默认设置为“仅访问本地文件”,但它可能不喜欢这一点。我希望这有用。
看:
http://www.adobe.com/livedocs/ flash/9.0/ActionScriptLangRefV3/flash/system/Security.html
Make sure your Global Security Settings in Flash Player allows local access to the directory.
Try this. Go to Publish Settings - Local playback security - choose "access network only." Flash CS4 default is "Access local files only" which it may not like. I hope this is useful.
See:
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/system/Security.html
我认为我们需要看到更多代码,但首先:“customobj”......你在哪里定义它?您在其他地方引用“customObject”。这是一个错字吗?如果该确切语句引发错误,则“customobj”很可能为空。
I think we'll need to see more code, but to start: "customobj" ... where are you defining that? You refer to "customObject" everywhere else. Is that a typo? If that exact statment is throwing the error then "customobj" is most likely null.
您使用的是 FlexBuilder/FlashDevelop 还是 flash IDE?
另外,你如何设置你的预加载器?
如果您使用 FlexBuilder/FlashDevelop 构建应用程序,您是否在编译器选项中指定了框架启动?
Are you using FlexBuilder/FlashDevelop or the flash IDE?
Also, how are you setting up your Preloader?
If you build your app with FlexBuilder/FlashDevelop, did you specify the frame start in your compiler options?
myMainApplication = new Application(customobj);
似乎同时成功和失败的原因是我没有完全理解try/catch
阻止的方式在 AS3 中运行。Application
的构造函数的子例程中抛出空指针异常,该异常发生在Application
检查以确保其接收到 customobj 的引用的代码之后。此错误被Main
中Application
实例周围的try/catch
块捕获,因为它是最近的封闭错误检查代码。希望我的错误能够避免其他人犯类似的错误!
The reason that
myMainApplication = new Application(customobj);
seemed to be succeeding and failing at the same time is that I didn't completely understand the way thetry/catch
blocks operate in AS3. There was a null pointer exception being thrown in a subroutine toApplication
's constructor, occurring after the code in whichApplication
checks to ensure it's receiving a reference to customobj. This error was being caught by thetry/catch
block surrounding the instantation ofApplication
inMain
, as it was the nearest enclosing error-checking code.Hopefully my mistake will save someone else for making a similar one!