2011-08-22 3 views
1

私はパーズリーフレームワークを使用しています。私は、カスタムビジュアルTreeコンポーネントにモデルを挿入しようとしています。ビジュアルコンポーネントの注入モデル

private var _model:Model 

[Bindable] 

public function get model():Model 
{ 
    return _model; 
} 

public function set model(value:Model):void 
{ 
    _model = value; 
} 

ビルド設定:

<Object id="customTree" type="{CustomTree}"> 
    <Property name="model" idRef="model"/> 
</Object> 

それから私は、MXMLでこの木を使用してい:

<components:CustomTree 
     id="categoriesTree" 
     width="100%" height="100%" 
     labelField="@title" 
     right="0" bottom="0" left="0" top="10"   
     doubleClickEnabled="true" 
     maxHorizontalScrollPosition="250" 
     horizontalScrollPolicy="auto" 
     dragEnabled="true" 
     dropEnabled="true" 
     dataProvider="{model.dataHolder}" 
     /> 

私はオーバーライド親機能を試していたと私はエラーを持っています。 (モデルはヌルです)。 override protected function dragDropHandler(event:DragEvent):void { model.action = "drop" }

モデルセッターにブレークポイントを設定して実行しましたが、モデルはまだヌルです。

問題はどこですか?

+0

投稿したコードは意味をなさないものでした。すべてを表示してください。さらに、あなたは何も注射していません。 –

+0

Build Configでモデルの構成を省略します。 – nkukhar

答えて

1

この問題を解決する方法を見つけました。ビジュアルコンポーネントにスムースを挿入しようとすると、ビジュアルコンポーネントを構成するのと同じ方法でスムーズを設定する必要があります。

public class CustomTree extends Tree 
{ 

public function CustomTree() 
{ 
    super(); 
    this.addEventListener(Event.ADDED_TO_STAGE, configure); 
} 

protected function configure(event:Event):void 
{ 
    this.dispatchEvent(new Event ('configureIOC', true)); 
} 

... }

Mbの誰かが他のいくつかのソリューションを持っていますか?

0

パーズリーがあなたのCustomTreeをインスタンス化することを確かめてください。 代わりにモデルをビューに挿入し、mxmlのCustomTreeインスタンスをモデルにバインドさせます。

設定:

<Object id="model" type="Model"/> 

MXML:

<mx:Script> 
     <![CDATA[ 
[Inject(id='model')] 
[Bindable] 
public var model:Model; 
]]> 
    </mx:Script> 

<components:CustomTree 
     id="categoriesTree" 
     width="100%" height="100%" 
     labelField="@title" 
     right="0" bottom="0" left="0" top="10"   
     doubleClickEnabled="true" 
     maxHorizontalScrollPosition="250" 
     horizontalScrollPolicy="auto" 
     dragEnabled="true" 
     dropEnabled="true" 
     dataProvider="{model.dataHolder}" 
     /> 

あなただけのモデルに注入タグと設定からIDをドロップし、あなたは、タイプによって注入可能性注入のためのIDは必要ありません。

+0

私はあなたを混乱させたと思う。私は、ModelをMXMLコンポーネントではなく、CustomTreeに注入する必要がありました。私はクラスを持っています - CustomTree.asこのクラスの中で私はモデルでいくつかのアクションを実行します。次に、mxmlでCustomTreeを使用しました。そして、うん、私はIDなしで注射できることを知っている。しかし、情報をありがとう。 – nkukhar

関連する問題