加载SWFLoader的.swf中的工具提示会导致错误#1009

时间:2014-03-25 14:25:03

标签: flex tooltip runtime-error swfloader

我正在开发一个flex web项目,其中许多功能都是模块化的,SWF加载了SWFLoader。我最近创建了一个模块,其中包含一些元素的工具提示,当我将鼠标悬停在这些元素上以查看工具提示时,我收到了运行时错误#1009。如果不是在运行时使用SWFLoader加载SWF,而是直接在应用程序中实例化它,工具提示工作正常。有谁知道这是为什么?

我正在使用Flex SDK 4.5.1,因为我必须使用的其中一个库不适用于更高版本。

我把这个问题分成了一个小例子。这是代码:

main mxml:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
               backgroundColor="#000000"
               creationComplete="onComplete(event);">
    <fx:Script>
        <![CDATA[
            import mx.controls.SWFLoader;
            import mx.events.FlexEvent;


            private function onComplete(event:FlexEvent):void {

                // Comment this block out to try without loading external swf
                var swfLoader:SWFLoader = new SWFLoader();
                swfLoader.addEventListener(Event.COMPLETE, swfLoadComplete);
                swfLoader.load("ExternalSWF.swf");

                // Uncomment this block to try without loading external swf ... Notice the tooltips suddenly work.. 
                /*var externalSwf:ExternalSWF = new ExternalSWF();
                this.addElement(externalSwf);*/
            }

            private function swfLoadComplete(event:Event):void {
                var externalSwf:ExternalSWF = (event.target as SWFLoader).content as ExternalSWF;
                this.addElement(externalSwf);
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
</s:Application>

ExternalSWF类(在Flash Builder 4.7中,设置为编译为模块):

package
{
    import spark.components.Button;
    import spark.components.VGroup;


    [Frame(factoryClass="ExternalSWF")]
    public class ExternalSWF extends VGroup
    {
        public function ExternalSWF()
        {
            super();
            var btn:Button = new Button();
            btn.label = "mouse over this";
            btn.toolTip = "moused over";

            this.addElement(btn);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

谢谢,宙斯。这让我走上了正确的道路,我能够解决我的问题。

这是一个解决方案:

main mxml AS代码:

private var _info:IModuleInfo;

private function onComplete(event:FlexEvent):void {
    _info = ModuleManager.getModule("ExternalSWF.swf");
    _info.addEventListener(ModuleEvent.READY, modEventHandler);      
    _info.load(null, null, null, moduleFactory);
}

private function modEventHandler(event:ModuleEvent):void {
    var externalSwf:ExternalSWF  = _info.factory.create() as ExternalSWF;
    this.addElement(externalSwf);
}

ExternalSWF

package
{
    import mx.controls.Button;

    import spark.modules.Module;


    public class ExternalSWF extends Module
    {
        public function ExternalSWF()
        {
            super();
            var btn:Button = new Button();
            btn.label = "mouse over this";
            btn.toolTip = "moused over";

            this.addElement(btn);
        }
    }
}