gpt4 book ai didi

apache-flex - 这是在 mxml 中调用组件方法的正确方法吗

转载 作者:行者123 更新时间:2023-12-04 02:30:12 25 4
gpt4 key购买 nike

我正在学习 Flex 并发现了一些奇怪的行为。当我尝试编译我的代码时,我抛出了这个错误 - 错误:调用可能未定义的方法 updateStory。我以前以这种方式使用过方法调用,但在这种情况下无法发现问题所在。这是该组件的代码:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script>
<![CDATA[

import mx.collections.ArrayCollection;

[Bindable]
public var storyCards:ArrayCollection;

private function updateStory():void
{
trace("success");
}

]]>
</mx:Script>

<mx:TileList dataProvider="{storyCards}" >

<mx:itemRenderer>

<mx:Component>

<mx:HBox>
<mx:Label />
<mx:TextInput keyUp="updateStory()" />
<mx:TextArea text="{data.notes}" />
</mx:HBox>

</mx:Component>

</mx:itemRenderer>

</mx:TileList>
</mx:Canvas>

谁能指出我正确的方向?

最佳答案

问题出在 mx:Component 父标签上。

来自 the docs:

The <mx:Component> tag defines a new scope within an MXML file, where the local scope of the item renderer or item editor is defined by the MXML code block delimited by the <mx:Component> and </mx:Component> tags. To access elements outside of the local scope of the item renderer or item editor, you prefix the element name with the outerDocument keyword.

因此您需要公开“updateStory”并添加 outerdocument 关键字,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[

import mx.collections.ArrayCollection;

[Bindable]
public var storyCards:ArrayCollection;

public function updateStory():void
{
trace("success");
}
]]>
</mx:Script>
<mx:TileList dataProvider="{storyCards}" >
<mx:itemRenderer>
<mx:Component>
<mx:HBox>
<mx:Label />
<mx:TextInput keyUp="outerDocument.updateStory()" />
<mx:TextArea text="{data.notes}" />
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:TileList>
</mx:Canvas>

关于apache-flex - 这是在 mxml 中调用组件方法的正确方法吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1637469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com