Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.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 在父mxml文档中将函数定义为公共函数时,如何从包含的.as文件调用该函数?_Actionscript 3_Flash_Apache Flex_Flash Builder - Fatal编程技术网

Actionscript 3 在父mxml文档中将函数定义为公共函数时,如何从包含的.as文件调用该函数?

Actionscript 3 在父mxml文档中将函数定义为公共函数时,如何从包含的.as文件调用该函数?,actionscript-3,flash,apache-flex,flash-builder,Actionscript 3,Flash,Apache Flex,Flash Builder,我有一个例子,我在FlashBuilder4.6(ApacheFlexSDK)中使用了一个include.as文件(可能会发布代码,但由于代码量太大,我认为这太过分了)。。。包含的文件有一些运行良好的AS3代码,但我刚刚添加了对父mxml文档中定义的函数的调用。。。我得到一个错误,报告included.as文件不知道函数是什么——好像它根本不存在 是否需要在函数调用的开头追加一些内容?我从几天前的另一个项目中了解到,在我第一次认真尝试使用itemrenderer时,我发现我必须使用outerDo

我有一个例子,我在FlashBuilder4.6(ApacheFlexSDK)中使用了一个include.as文件(可能会发布代码,但由于代码量太大,我认为这太过分了)。。。包含的文件有一些运行良好的AS3代码,但我刚刚添加了对父mxml文档中定义的函数的调用。。。我得到一个错误,报告included.as文件不知道函数是什么——好像它根本不存在

是否需要在函数调用的开头追加一些内容?我从几天前的另一个项目中了解到,在我第一次认真尝试使用itemrenderer时,我发现我必须使用outerDocument。在函数的前面。。。i、 e-

outerDocument.MyFunctionNameHere();
只要我的父文档将函数定义为公共函数,它就应该对included.as文件中的代码“可见”,对吗?

希望这会有所帮助

includes.as-包含文件

// ActionScript file
public function includedFunction(item:Object):String{
    var data = parentFunction(item); //call function from parent mxml
    return data;
}
AS3方式(但不可绑定)


正确的方法

<fx:Script source="includes.as" />
<fx:Script>
    <![CDATA[   
    public function parentFunction(data:Object):String{             
        return "Hello From Main MXML";
    }
    ]]>
</fx:Script>
<s:DataGrid dataProvider="{new ArrayCollection(new Array(1,2,3))}">
    <s:columns>
        <s:ArrayList>
           <s:GridColumn>
             <s:itemRenderer>
                <fx:Component>
                  <s:GridItemRenderer>
                    <s:Label text="{outerDocument.includedFunction(data)}"/>
                  </s:GridItemRenderer>
                </fx:Component>
             </s:itemRenderer>
           </s:GridColumn>
        </s:ArrayList>          
     </s:columns>
</s:DataGrid>


由于基本的封装原理;子文档不应直接调用父文档上的方法。这篇博文对你有帮助吗@Reboog711现在我退一步考虑一下,这是有道理的。。。这个网址确实很有用-谢谢。
<fx:Script source="includes.as" />
<fx:Script>
    <![CDATA[   
    public function parentFunction(data:Object):String{             
        return "Hello From Main MXML";
    }
    ]]>
</fx:Script>
<s:DataGrid dataProvider="{new ArrayCollection(new Array(1,2,3))}">
    <s:columns>
        <s:ArrayList>
           <s:GridColumn>
             <s:itemRenderer>
                <fx:Component>
                  <s:GridItemRenderer>
                    <s:Label text="{outerDocument.includedFunction(data)}"/>
                  </s:GridItemRenderer>
                </fx:Component>
             </s:itemRenderer>
           </s:GridColumn>
        </s:ArrayList>          
     </s:columns>
</s:DataGrid>