Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 随机生成SWFLoader源_Actionscript 3_Flash_Apache Flex_Mxml_Swfloader - Fatal编程技术网

Actionscript 3 随机生成SWFLoader源

Actionscript 3 随机生成SWFLoader源,actionscript-3,flash,apache-flex,mxml,swfloader,Actionscript 3,Flash,Apache Flex,Mxml,Swfloader,我想在flex中创建一个视图,显示随机生成的swf。 以下代码可以运行,但我的swf没有显示?如何解决这个问题 <fx:Script> <![CDATA[ public function random(url:String):String{ var movieArray:Array = ['swf/maily_you', 'swf/maily_work', 'swf/maily_start']; va

我想在flex中创建一个视图,显示随机生成的swf。 以下代码可以运行,但我的swf没有显示?如何解决这个问题

<fx:Script>
    <![CDATA[   
        public function random(url:String):String{
            var movieArray:Array = ['swf/maily_you', 'swf/maily_work', 'swf/maily_start'];
            var loader:Loader = new Loader(); 
            var index:int = movieArray.length * Math.random(); 
            var url:String = movieArray[index] + '.swf'; 
            trace("Attempting to load", url); 
            loader.load(new URLRequest(url));
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderComplete); 
            loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loaderIOError); 
            addChild(loader); 
            function loaderComplete(e:Event):void {     
                trace("Successfully loaded", url);
            } function loaderIOError(e:IOErrorEvent):void {     
                trace("Failed to load", url); 
            }
    ]]>
</fx:Script>
<s:Panel width="100%" height="100%">
    <mx:SWFLoader  width="480" height="320" id="loader1" source="random()"/> 
</s:Panel>

在您发布的代码中,您有一些小错误:

  • 如果您想让
    random()
    函数设置
    SWFLoader
    对象的源,它应该返回SWF的URL,而不是将其用作参数
  • 标签:

    
    

    因此,您的最终代码可以如下所示:

    <fx:Script>
        <![CDATA[   
            public function random():String 
            {
                var movieArray:Array = ['swf/maily_you', 'swf/maily_work', 'swf/maily_start'];
                var loader:Loader = new Loader(); 
                var index:int = movieArray.length * Math.random(); 
                var url:String = movieArray[index] + '.swf'; 
                return url;
            }
        ]]>     
    </fx:Script>
    <s:Panel width="100%" height="100%">
        <mx:SWFLoader  width="480" height="320" id="loader1" source="random()"/> 
    </s:Panel>
    
    
    
    更多信息,请查看


    希望能有所帮助。

    URL看起来真的不错吗?如果没有,则放入
    跟踪(“从数组索引获取:+index”)在尝试加载之前。你得到了什么?也可以考虑(只是为了测试)把这3个SWF放在同一个文件夹中作为这个程序SWF(检查它是否是一个文件夹路径/访问问题),所以如果你可以加载<代码>邮件yYu.SWF 但不是<代码> SWF/MayyYuU.SWF 你可以知道使用绝对URL(即:完整路径名)
    
    <mx:SWFLoader width="480" height="320" id="loader1" source="{random()}"/>
    
    <fx:Binding 
        source="random()"
        destination="loader1.source"
    />
    <mx:SWFLoader  width="480" height="320" id="loader1" source=""/>
    
    <fx:Script>
        <![CDATA[   
            public function random():String 
            {
                var movieArray:Array = ['swf/maily_you', 'swf/maily_work', 'swf/maily_start'];
                var loader:Loader = new Loader(); 
                var index:int = movieArray.length * Math.random(); 
                var url:String = movieArray[index] + '.swf'; 
                return url;
            }
        ]]>     
    </fx:Script>
    <s:Panel width="100%" height="100%">
        <mx:SWFLoader  width="480" height="320" id="loader1" source="random()"/> 
    </s:Panel>