0

I have a case where I am using an included .as file in flashbuilder 4.6 (apache flex sdk) (would post code but due to the size of the amount of code I think it would be overkill)... the included file has some AS3 code that runs fine, but I just added a call to a function that's defined in the PARENT mxml document... I get an error that's reporting that the included .as file doesn't know what the function is -- as if it doesn't exist at all.

Is there something I need to append the beginning of the function call? I know from another project a few days back I discovered during some work on one of my first serious itemrenderer attempts that I had to use outerDocument. at the front of the function ... i.e -

outerDocument.MyFunctionNameHere();

as long as my parent document has the function defined as a public function, it should be 'visible' to the code in the included .as file, right?

4

1 回答 1

0

希望这会有所帮助。

includes.as - 包含文件

// ActionScript file
public function includedFunction(item:Object):String{
    var data = parentFunction(item); //call function from parent mxml
    return data;
}

AS3方式(但不可绑定)

<fx:Script>
    <![CDATA[        
    include "includes.as";

    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'].call(null, new Array(data))}"/>
                  </s:GridItemRenderer>
                </fx:Component>
             </s:itemRenderer>
           </s:GridColumn>
        </s:ArrayList>          
     </s:columns>
</s:DataGrid>

合适的方式

<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>
于 2013-07-15T21:17:08.177 回答