Flex 3(动作脚本):如何从加载的 swf 文件访问函数?
我在 ActionScript 中加载一个 swf 文件。到目前为止没有问题,但我没有找到一种方法来访问它的其中一个函数,最好的事情是如果我可以访问 swf 的 mxml 部分中的主函数。
以下是属于应加载和访问另一个 swf 的 swf 的 main-mxml 文件的代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="basket();">
<mx:Script>
<![CDATA[
import mx.controls.SWFLoader;
private function basket(): void
{
var swfLoader: SWFLoader = new SWFLoader();
swfLoader.addEventListener( Event.COMPLETE, handleSWFLoaded );
try {
swfLoader.load( "../../data/InternalSWF.swf" );
} catch (error: Error) {
trace( "Couldn't load file !" );
}
}
private function handleSWFLoaded( event: Event ): void
{
var swfApp:* = event.target.content;
// This both ways don't work...
//if (swfApp.hasOwnProperty("initApp")) {
// var initApp:Function = (swfApp["initApp"] as Function);
// initApp();
//}
// swfApp.initApp();
}
]]>
</mx:Script>
<mx:Text id="output" width="100%" textAlign="center" />
</mx:Application>
if 语句“if (swfApp.hasOwnProperty("initApp")) {”永远不会为 true,并且 调用“swfApp.initApp()”表示该函数不存在。
在原始版本中,我添加了 HTTPStatusEvent.HTTP_STATUS、IOErrorEvent.IO_ERROR 和 SecurityErrorEvent.SECURITY_ERROR 的事件侦听器。但除了 HTTP_STATUS = 0 之外,它们都不会被调用。
我尝试做这件事的整个想法是错误的吗?
i load in ActionScript a swf file. So far no Problem, but I didn't found a way to access one of it's functions, the best thing would be if I could access the main function in the mxml part of the swf.
Here is the code of the main-mxml file that belongs to the swf that should load and access another swf:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="basket();">
<mx:Script>
<![CDATA[
import mx.controls.SWFLoader;
private function basket(): void
{
var swfLoader: SWFLoader = new SWFLoader();
swfLoader.addEventListener( Event.COMPLETE, handleSWFLoaded );
try {
swfLoader.load( "../../data/InternalSWF.swf" );
} catch (error: Error) {
trace( "Couldn't load file !" );
}
}
private function handleSWFLoaded( event: Event ): void
{
var swfApp:* = event.target.content;
// This both ways don't work...
//if (swfApp.hasOwnProperty("initApp")) {
// var initApp:Function = (swfApp["initApp"] as Function);
// initApp();
//}
// swfApp.initApp();
}
]]>
</mx:Script>
<mx:Text id="output" width="100%" textAlign="center" />
</mx:Application>
The if-Statement "if (swfApp.hasOwnProperty("initApp")) {" is never true and
the call "swfApp.initApp()" says that this function does not exist.
In the original version I added event listeners for HTTPStatusEvent.HTTP_STATUS, IOErrorEvent.IO_ERROR and SecurityErrorEvent.SECURITY_ERROR. But except for HTTP_STATUS = 0 none of them are called.
Is the whole idea of how i try to do this wrong ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在帖子发布几天后找到了解决方案:)
加载 swf 后,您可以使用以下代码访问内部函数(在本例中为 initApp()):
Found a solution some days after the post :)
After the swf is loaded you can use the following code to access the internal functions (in this example initApp()):