ASP.NET
  Home arrow ASP.NET arrow Page 2 - Developing a Dice Game Using ASP.NET Futur...
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Developing a Dice Game Using ASP.NET Futures Drag and Drop Techniques
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2008-04-09

    Table of Contents:
  • Developing a Dice Game Using ASP.NET Futures Drag and Drop Techniques
  • Defining the two behaviors: MagicDragSourceBehavior and MagicDropTargetBehavior
  • MagicDropTargetBehavior
  • HTML code-related programming
  • XML-Script programming
  • JavaScript programming

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    IBM developerWorks
     
    ADVERTISEMENT

    AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th -1:00PM EST. Register Today!

    Developing a Dice Game Using ASP.NET Futures Drag and Drop Techniques - Defining the two behaviors: MagicDragSourceBehavior and MagicDropTargetBehavior


    (Page 2 of 6 )

    Obviously, the six dice represent the drag sources. Therefore, we can define a custom behavior named MagicDragSourceBehavior. By attaching this behavior to the six client-side controls that are associated with the six dice, we can make the six die-related DOM elements draggable.

    For analysis, we list the source code of MagicDragSourceBehavior, which is shown below:

    Type.registerNamespace('Custom.UI');

    Custom.UI.MagicDragSourceBehavior = function(element)

    {

    Custom.UI.MagicDragSourceBehavior.initializeBase(this, [element]);

    //defined the mousedown event listener

    this._mouseDownHandler = Function.createDelegate(this,

    this.mouseDownHandler);

    this._dragDropMagic=null;

    this._visual = null;

    }

    Custom.UI.MagicDragSourceBehavior.prototype =

    {

    get_dragDropMagic: function()

    {

    return this._dragDropMagic;

    },

    set_dragDropMagic: function(dragDropMagic)

    {

    this._dragDropMagic = dragDropMagic;

    },

    //get the data type of the draggable object

    //here we specify the data type must be DragDropMagic

    get_dragDataType: function()

    {

    return 'DragDropMagic';

    },

    //get the data that is held in the draggable object

    getDragData: function(context)

    {

    return this._dragDropMagic;

    },

    //specify the drag mode to be ‘Copy’

    get_dragMode: function()

    {

    return Sys.Preview.UI.DragMode.Copy;

    },

    onDragStart: function() {},

    onDrag: function() {},

    // onDragEnd is called at the end of the drag & drop operation

    // Here, delete the semitransparent object that shows

    // the process of dragging and reconstruct it when needed

    onDragEnd: function(canceled)

    {

    if (this._visual)

    this.get_element().parentNode.removeChild(this._visual);

    },

    initialize: function()

    {

    Custom.UI.MagicDragSourceBehavior.callBaseMethod(this,'initialize');

    $addHandler(this.get_element(), 'mousedown',this._mouseDownHandler)

     

    },

    //mousedown event handler

    //Note the following code is quite similar to that used inside the onDragEnd method of the DragDropList behavior

    mouseDownHandler: function(ev)

    {

    window._event = ev; //DragDropManager needs this

    this._visual = this.get_element().cloneNode(true);

    this._visual.style.opacity = '0.4';

    this._visual.style.filter =

    'progid:DXImageTransform.Microsoft.BasicImage(opacity=0.4)';

    this._visual.style.zIndex = 99999;

    this.get_element().parentNode.appendChild(this._visual);

    var location =Sys.UI.DomElement.getLocation(this.get_element());

    Sys.UI.DomElement.setLocation(this._visual, location.x,location.y);

    Sys.Preview.UI.DragDropManager.startDragDrop(this,this._visual, null);

    },

    dispose: function()

    {

    if (this._mouseDownHandler)

    $removeHandler(this.get_element(), 'mousedown',this._mouseDownHandler);

    this._mouseDownHandler = null;

    Custom.UI.MagicDragSourceBehavior.callBaseMethod(this, 'dispose');

    }

    }

    //define the descriptor block so as to be used in xml-script programming

    Custom.UI.MagicDragSourceBehavior.descriptor = {

    properties: [

    {name: 'dragDropMagic', type: Custom.UI.DragDropMagic}

    ]

    }

    Custom.UI.MagicDragSourceBehavior.registerClass

    ('Custom.UI.MagicDragSourceBehavior', Sys.UI.Behavior,

    Sys.Preview.UI.IDragSource);

    As for MagicDragSourceBehavior, the following points deserve to be mentioned:

    1. This behavior is defined within the Custom.UI namespace.

    2. The private variable _visual serves the same role as the private variable _dragVisual and is defined within the DragDropList behavior. These are all used to create a semitransparent element that indicates the drag & drop process.

    3. The dragDropMagic propertyis very important. It corresponds to thedata propertyused inside the DragDropList behavior. In this sample, this property is used to store our custom object—Custom.UI.DragDropMagic (for brevity, we have not listed its source code; you can refer to the downloadable source code of the article), which defines two properties:backgroundColorandnumber. These represent the background color of the drop area and the dot number that is shown. Please note the relationship between this property and the data within MagicDropTargetBehavior. It will be defined later.

    4. As for the methods declared in IDragSource, here we have defined them with those unused in this empty sample.

    5. At the end of the event handler, mouseDownHandler, the following method is invoked:

    Sys.Preview.UI.DragDropManager.startDragDrop(this,this._visual, null);

    This method is responsible for notifying DragDropManager that the drag & drop operation has already started.

    6. To use MagicDragSourceBehavior inside the declarative XML-Script blocks, we have also defined its descriptor with only adragDropMagic propertyexposed (as is explained above).

    More ASP.NET Articles
    More By Xianzhong Zhu


     

    ASP.NET ARTICLES

    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ
    - Developing a Dice Game Using ASP.NET Futures...
    - Completing an ASP.NET AJAX Server-Centric Ba...
    - Information Management for an ASP.NET AJAX S...
    - Comment and Order Management for an ASP.NET ...
    - Back-end Management Tasks for an ASP.NET AJA...
    - User Information Management for an ASP.NET A...
    - Adding Comments and Search to an ASP.NET AJA...
    - Order-Related Modules for an ASP.NET AJAX Se...
    - User and Role Management for an ASP.NET AJAX...
    - Programming an ASP.NET AJAX Server-Centric B...

    BlackBerry VTS




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway