Hi all,
I am trying to add remove button and on the click calling a function
using outerdocument scope. This is the code.......
----------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Metadata>
[Event(name="productRemoved",type="events.ProductEvent")]
</mx:Metadata>
<mx:Script>
<![CDATA[
import events.ProductEvent;
import valueObjects.ShoppingCart;
import valueObjects.ShoppingCartItem;
import valueObjects.Product;
import mx.controls.dataGridClasses.DataGridColumn;
import valueObjects.Category;
[Bindable]
public var cart:ShoppingCart;
private function
renderPriceLabel(item:ShoppingCartItem,dataField:DataGridColumn):String{
return "$"+String(item.subtotal);
}
public function
removeItem(cartItem:ShoppingCartItem):void{
var prod:Product = cartItem.product;
var e:ProductEvent = new
ProductEvent(prod,"productRemoved");
this.dispatchEvent(e);
}
]]>
</mx:Script>
<mx:DataGrid
id="cartView"
dataProvider="{cart.aItems}" width="100%" height="100%"
editable="true" draggableColumns="false"
variableRowHeight="true">
<mx:columns>
<mx:DataGridColumn dataField="product"
headerText="Product"
itemRenderer="renderer.ecomm.ProductName"
editable="false"/>
<mx:DataGridColumn dataField="quantity"
itemEditor="mx.controls.NumericStepper"
editorDataField="value" editable="true"
headerText="Quantity" />
<mx:DataGridColumn dataField="subtotal"
headerText="Amount"
labelFunction="renderPriceLabel" editable="false" />
<mx:DataGridColumn editable="false">
<mx:itemRenderer>
<mx:Component>
<mx:VBox>
<mx:Button
label="Remove"
click="outerDocument.removeItem(valueObjects.ShoppingCartItem(data));"/>
</mx:VBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:VBox>
-----------------------------------------------------------------------------------------------------------------
Its giving an error saying
Access of undefined property valueObjects. Line 51
the coding for the Shoppingcartitem is as follows
package valueObjects
{
public class ShoppingCartItem
{
public var product:Product;
private var _quantity:uint;
public var subtotal:Number;
public function ShoppingCartItem(product:Product,
quantity:uint=1){
this.product = product;
this.quantity = quantity;
this.subtotal = product.listPrice * quantity;
}
public function recalc():void{
this.subtotal = product.listPrice * quantity;
}
public function set quantity(qty:uint):void{
_quantity = qty;
recalc();
}
public function get quantity():uint{
return _quantity;
}
public function toString():String{
return this.quantity.toString() + ": " +
this.product.prodName;
}
}
}
Can anyone help me out........
--
Thanx & Regards,
Rajiv Gupta
Mobile:+919988197704