Flex 3(动作脚本):如何从加载的 swf 文件访问函数?

发布于 2024-09-01 00:49:26 字数 1655 浏览 3 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伊面 2024-09-08 00:49:26

在帖子发布几天后找到了解决方案:)

加载 swf 后,您可以使用以下代码访问内部函数(在本例中为 initApp()):

public function getInnerSWF():Object
{
  var sysMan:SystemManager = swfLoader.content as SystemManager;<br>
        return sysMan.document;
}

getInnerSWF().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()):

public function getInnerSWF():Object
{
  var sysMan:SystemManager = swfLoader.content as SystemManager;<br>
        return sysMan.document;
}

getInnerSWF().initApp();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文