从 Flex 访问 SWF 方法

发布于 2024-11-17 04:26:30 字数 655 浏览 4 评论 0原文

在尝试了几乎所有我遇到的例子后,我都碰壁了。我希望这里有人能够帮助我。

简而言之,我有一个 Flex 父级,它嵌入了一个 Flash SWF 文件,该文件具有需要从 Flex 访问的方法。

MXML:

    <mx:states>

        <mx:State name="intro">
            <mx:AddChild position="lastChild">
                <mx:SWFLoader x="285" y="170" id="introSwfLoader" source="@Embed(source='Introduction.swf')" />
            </mx:AddChild>
        </mx:State> 

我尝试过将 SWFLoader 强键入为 MovieClip 来获得对它的控制,但没有成功。

Flash:

function reset(){

    // some code
}

有人有什么建议吗?基本上,我需要做的就是在 mx:State 更改时重置/重新加载 Flash SWF。

谢谢你的时间..

I have hit a brick wall after trying almost every example I have come accross. I was hoping that someone here might be able to help me.

In a nutshell I have a Flex parent which is embedding a Flash SWF file which has a Method which needs to be accessed from Flex.

MXML:

    <mx:states>

        <mx:State name="intro">
            <mx:AddChild position="lastChild">
                <mx:SWFLoader x="285" y="170" id="introSwfLoader" source="@Embed(source='Introduction.swf')" />
            </mx:AddChild>
        </mx:State> 

I have tried strong typing the SWFLoader as a MovieClip to gain control of it but have had no luck.

Flash:

function reset(){

    // some code
}

Does anyone have any suggestions? Essentially all I need to do is reset/reload the Flash SWF when the mx:State changes.

Thanks for your time..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

又爬满兰若 2024-11-24 04:26:30

您不应该需要 LocalConnection。

试试这个 - 这不是最优雅的解决方案,但这似乎可行 - 在 Flex 应用程序中的某些方法中,您可以通过这种方式将加载的 SWF 作为 MovieClip 访问:

function accessLoadedSWFAsMovieClip():void{
    var container:DisplayObjectContainer = introSwfLoader.content as DisplayObjectContainer; //gets the SWFLoader content as a DisplayObjectContainer
    var loader:Loader  = container.getChildAt (0) as Loader; // gets the first child of the DisplayObjectContainer, which is a Loader (not sure why)
    var mc:MovieClip = loader.content as MovieClip; //access to the main timeline of the Loader's content (cast as a MovieClip, because we can then call ambiguous functions with no errors. I assume if your loaded swf had a document class you could cast it as the document class here)
    mc.reset(); // call the function inside our loaded SWF
}

You shouldn't need LocalConnection.

Try this - it's not the most elegant solution but this seems to work - in some method in your Flex app, you can access the loaded SWF as a MovieClip this way:

function accessLoadedSWFAsMovieClip():void{
    var container:DisplayObjectContainer = introSwfLoader.content as DisplayObjectContainer; //gets the SWFLoader content as a DisplayObjectContainer
    var loader:Loader  = container.getChildAt (0) as Loader; // gets the first child of the DisplayObjectContainer, which is a Loader (not sure why)
    var mc:MovieClip = loader.content as MovieClip; //access to the main timeline of the Loader's content (cast as a MovieClip, because we can then call ambiguous functions with no errors. I assume if your loaded swf had a document class you could cast it as the document class here)
    mc.reset(); // call the function inside our loaded SWF
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文