Drag & Drop to a DustBin & increase count in Datagrid

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" 
	width="100%" height="100%" backgroundColor="white">
	<mx:Label x="0" y="210" text="Games"
    width="118" height="42" fontSize="28" color="#818181"/>
    <mx:Style source="styles.css"/>
  	import mx.collections.ArrayCollection;
  	import mx.events.DragEvent;
  	import mx.core.DragSource;
  	import mx.controls.Image;
  	import mx.managers.DragManager;

  private var bioshock_icon:Class;

  private var crysis_icon:Class;

  private var halo_icon:Class;

  private var neverwinter_icon:Class;

  private var wow_icon:Class;

  private var basket:Class;
 private var cartContents:ArrayCollection = new ArrayCollection();
 private function doDrag(event:MouseEvent):void
  var img:Image = event.currentTarget as Image;
  var dragImg:Image = new Image();
  dragImg.source = img.source;
  var dsource:DragSource = new DragSource();
  dsource.addData(img, 'img');
  DragManager.doDrag(img, dsource, event, dragImg);
private function dragAccept(event:DragEvent):void
  var dropTarget:Canvas = event.currentTarget as Canvas;
private function dragDrop(event:DragEvent):void
  var img:Image = event.dragSource.dataForFormat('img') as Image;
private function addToCart(img:Image):void
  for(var i:int = 0; i <cartContents.length; i++)
    if(cartContents[i].name == img.name)
  cartContents.addItem(new Game(img.name,1));
     <mx:Image name="img1" x="0" y="0" source="{basket}" width="100" height="200"/>
<mx:HBox width="100%" horizontalCenter="0">
  <mx:Image name="Bioshock" x="2" y="2"
    source="{bioshock_icon}" mouseDown="doDrag(event)" />
<mx:Image name="Crysis" x="120" y="2"
    source="{crysis_icon}" mouseDown="doDrag(event)" />
  <mx:Image name="Halo" x="340" y="2"
    source="{halo_icon}" mouseDown="doDrag(event)" />
  <mx:Image name="Neverwinter Nights" x="50" y="200"
    source="{neverwinter_icon}" mouseDown="doDrag(event)" />
  <mx:Image name="World of Warcraft" x="200" y="110"
    source="{wow_icon}" mouseDown="doDrag(event)" />
  <mx:Label x="272" y="235" text="Shopping Cart" color="#3A3A3A"
    fontWeight="bold" fontSize="12"/>
	<mx:Canvas width="100" height="100" styleName="GradientCanvas">
  <mx:Canvas  width="175" height="150" styleName="GradientCanvas"
    borderStyle="solid" backgroundColor="#12976A"
    dragEnter="dragAccept(event)" horizontalScrollPolicy="off" verticalScrollPolicy="off"
    dragDrop="dragDrop(event)" >
  <mx:Image id="i1" name="img1" source="{basket}" width="175" height="195"/>
  <mx:DataGrid dataProvider="{cartContents}" x="173" y="255" width="201" height="151">
      <mx:DataGridColumn headerText="Name" dataField="name"/>
      <mx:DataGridColumn headerText="Quantity" dataField="num" width="65"/>
  public class Game
    public var name:String;
    public var num:Number;

    public function Game(name:String, num:Number)
      this.name = name;
      this.num = num;
}// ActionScript file

~ by mjcprasad2000 on January 16, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: