创建完成的替代方法

时间:2010-07-04 20:30:34

标签: flex

我正在尝试将一堆产品细节加载到List组件的canvas组件中。

每次用户点击我的列表中的产品时,产品详细信息都将显示在画布组件中。产品详细信息可能包含null,我想在显示在canvas组件中之前检查它。

在我的canvas组件中,我使用createcomplete检查productDetail == null然后执行某些操作。我的问题是,如果用户第一次点击非空详细信息的产品,如果用户单击一个空产品详细信息,因为画布组件已被删除,语句“if(productDetail == null)然后执行某些操作”将不起作用用户第一次单击非空产品详细信息时创建。

我想在每次用户点击产品时检查productDetail == null ...我希望我能很好地解释我的问题并感谢任何帮助。

我的代码..

AS

protected function changeHandler(event:IndexChangeEvent):void{

   compDetailinfoResult.token=getCompList.compDetail(event.target.selectedItem.productId);//get the product detail clicked by the user

}


<s:List dataProvider={productData}/>  //when user click a product, 
                                      //the canvas will show product detail..

<comp:productDetail productData={compDetailinfoResult.lastResult} //custom property 
                    change="changeHandler"/>  //if the product detail is 
                 //null, the statement inside 
                 //the canvas will check via 
                 //creationComplete. but if the 
                 //user click the non-null product, 
                 //the creationComplete check pass. User clicks a null product again,  
                 //the check won't work anymore...

我的productDetail组件的代码:

public var productData:arrayCollection

protected function canvas1_creationCompleteHandler(event:FlexEvent):void
{
var undefinedBrand:String=dataFromClick.getItemAt(0).brand;

    if(undefinedBrand==null){   // I want to check every time the user click a List item
      brand.text="Brand: No Brand";
      switchView.enabled=false;
      displayPictureBig.source="assets/vacant.jpg";
     }
}

    <s:Panel>
       <label id="brand" text="productDate.getItemAt(0).brand"/> 
//I want the brand to be displayed..
//but if brand is null..it will display No Brand..
//see AC above...but createComplete only fire once.
//Anyway to keep tracking if the brand that is sent by List is null?
    </s:Panel

感谢帮助..

1 个答案:

答案 0 :(得分:1)

我在理解你的问题时遇到了一些麻烦。你明确提到了Canvas Halo容器吗?或者您是否将自定义组件命名为Canvas?如果它是自定义的,正如您的代码所示,组件内部是什么?

creationComplete是一个事件,只有当组件第一次完成组件生命周期创建过程的运行时才会触发一次。您的代码段不会显示从列表传递到画布的任何数据,因此这可能是数据为空的一个原因。

如果有人在列表中选择了新项目,则change事件应该发送。您可以向change事件添加事件侦听器,并使用它来更新要发送到canvas组件的数据。

相关问题