0

私はフレックスが初めてで、これを機能させることができないようです。基本的に、利用可能なデータが別のコンボボックスに依存する選択ボックスがあります。

各 CategoryType には複数の TreatmentType があります。

これが私のコードです:

コンボボックスの変更; 選択ボックスの更新:

private function refreshAvailableTreatmentTypes():void {
        // this is the combo box
        fAccomplishment.habitatType = habitatTypeId.selectedIndex != -1 ? habitatTypeId.selectedItem as HabitatType : null; 
        // fAccompRemote is a RemoteObject
        var treatmentList:ArrayCollection = fAccompRemote.getValidTreatments(fAccompForm.accomplishment, fAccomplishment.habitatType);

        if ( fAccompForm.categoryTypes != null ) {
            // All categories are always shown. These are passed to the form on construction. 
            for each ( var currentCat:CategoryType in fAccompForm.categoryTypes ) {
                var catAdded:Boolean = false;
                /* loop through all the treatments in each Category and add them to 
                 * the available list if they meet the criteria */
                for each ( var currentTreat:TreatmentType in currentCat.treatments ) {
                    if (currentTreat.id in treatmentList || treatmentList.length == 0) {
                        if (!catAdded) {
                            // fCatsAndTreats defined as a [Bindable] private var
                            fCatsAndTreats.addItem( currentCat );
                            catAdded = true;
                        } 

                        fCatsAndTreats.addItem( currentTreat );
                    }
                }
            }
        }
    }

サービス方法:

@RemotingInclude
public List<TreatmentType> getValidTreatments(Accomplishment accomp, HabitatType selectedHabitatType){
    if ( accomp == null || accomp.getGeometry() == null || accomp.getHabitatType() == null) {
        return new ArrayList<TreatmentType>();
    }

    Geometry accompGeo = accomp.getGeometry();
    List<TreatmentType> optionList = new ArrayList<TreatmentType>();
    String geomName = null;

    if ( accompGeo instanceof Point || accompGeo instanceof MultiPoint ) {
        geomName = "Point";
    } else if ( accompGeo instanceof LineString || accompGeo instanceof MultiLineString) {
        geomName = "Line";
    } else if ( accompGeo instanceof Polygon || accompGeo instanceof MultiPolygon ) {
        geomName = "Polygon";
    }

    Integer habTypeId = null;
    if (selectedHabitatType == null) {
        habTypeId = accomp.getHabitatType().getId();
    } else {
        habTypeId = selectedHabitatType.getId();
    }
    optionList = accomplishmentDao.getValidTreatments(geomName, habTypeId);

    return optionList;
}

TypeError: エラー #1034: 型強制に失敗しました: mx.rpc::AsyncToken@1af48641 を mx.collections.ArrayCollection に変換できません。

どうすればいいですか?これを見つけましたが、あまり役に立たないようです: . リソースや情報をいただければ幸いです。

4

1 に答える 1

2

RemoteObject の呼び出しは非同期です。fAccompRemote.getValidTreatments からの戻り値は AsyncToken であり、結果 (返されたとき) の処理方法を定義します。

リモート呼び出しが戻ると、呼び出しが成功したか失敗したかに応じて、結果ハンドラーまたは障害ハンドラーのいずれかが呼び出されます。

コードの応答ハンドラーを設定するには、いくつかの方法があります。呼び出しに EventListener を追加するか、呼び出しから返された AsyncToken にレスポンダーを設定します。

fAccompRemote.addEventListener(ResultEvent.RESULT, resultHandler);
fAccompRemote.getValidTreatments(...)

-また-

var token:AsyncToken = fAccompRemote.getValidTreatments(...);
token.addResponder(new AsyncResponder(resultHandler, faultHandler));

いずれの場合も、resultHandler返された ArrayCollection を使用して ResultEvent イベントを受け取りますgetValidTreatments

protected function resultHandler(event:ResultHandler):void
{
    var results:ArrayCollection = event.result as ArrayCollection;
}
于 2014-05-05T20:38:46.287 に答える