次の構造のarrayCollectionがあります。
projectErrorsAC
0
project1number
project2number
position1number
position2number
project1name
project2name
student
1
...
ACは次のように定義されます。
[Bindable] private var projectErrorsAC:ArrayCollection = new ArrayCollection;
このACをリピーターで使用して、各エラーを表示しています。各エラーが表示された後、「承認」ボタンと「拒否」ボタンを配置しました。ユーザーがこれらのボタンのいずれかをクリックしたら、ACから特定のエラーを削除する関数を呼び出したいと思います。これが私がこれまでに持っているものです:
リピータ:
<mx:Repeater id="projRP" width="100%" dataProvider="{projectErrorsAC}">
<mx:HBox>
<mx:Text id="projmsg" text="{projRP.currentItem.student} is working on the following projects on the same day: {projRP.currentItem.proj1name} and {projRP.currentItem.proj2name}." />
<mx:Text id="allow" text="Allow" color="#ff0000" selectable="false"
click="acceptProjConflict(projRP.currentItem);"
mouseOver="parentApplication.switchCursor(true);"
mouseOut="parentApplication.switchCursor(false);" />
<mx:Text text=" |" />
<mx:Text id="decline" text="Decline" color="#ff0000" selectable="false" click="declineProjConflict(projRP.currentItem);" mouseOver="parentApplication.switchCursor(true);" mouseOut="parentApplication.switchCursor(false);" />
</mx:HBox>
</mx:Repeater>
これが「クリック」部分で呼び出している関数です。
public function acceptProjConflict(conflict:Object):void
{
for (var i:int = 0; i < projectErrorsAC.length; i++)
{
if (projectErrorsAC.getItemAt(i) == conflict)
projectErrorsAC.removeItemAt(i);
}
}
何らかの理由で、これは機能していません...
* 編集 *
成功!
リピーター内に配置するモジュールを作成する必要がありました。リピーターは次のようになります。
<mx:Repeater id="projRP" width="100%" dataProvider="{projectErrorsAC}">
<conflict:showErrors id="projErrors" thisObject="{projRP.currentItem}" isProject="true"/>
</mx:Repeater>
私のモジュールは次のようになります。
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">
<mx:Script>
<![CDATA[
public var isProject:Boolean;
public var thisObject:Object;
[Bindable] public var displayString:String = new String;
private function init():void
{
if (isProject)
{
displayString = thisObject.student + " is working on the following projects on the same day: " + thisObject.proj1name + " and " + thisObject.proj2name + ".";
}
}
]]>
</mx:Script>
<mx:Canvas width="750">
<mx:HBox>
<mx:Text id="projmsg" text="{displayString}" />
<mx:Text id="allow" text="Allow" color="#ff0000" selectable="false" click="parentDocument.acceptProjConflict(thisObject)" mouseOver="parentApplication.switchCursor(true);" mouseOut="parentApplication.switchCursor(false);" />
<mx:Text text=" |" />
<mx:Text id="decline" text="Decline" color="#ff0000" selectable="false" click="parentDocument.declineProjConflict(thisObject);" mouseOver="parentApplication.switchCursor(true);" mouseOut="parentApplication.switchCursor(false);" />
</mx:HBox>
</mx:Canvas>
</mx:Module>