ASP.NET
  Home arrow ASP.NET arrow Page 3 - Developing a Dice Game Using ASP.NET Futur...
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 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM developerWorks
 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
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Developing a Dice Game Using ASP.NET Futures Drag and Drop Techniques - MagicDropTargetBehavior


    (Page 3 of 6 )


    Next, let’s take a look at the second behavior—MagicDropTargetBehavior, which will be attached to the droppable area in the dice game. The following is the total source code for MagicDropTargetBehavior:

    //constructor definition

    Custom.UI.MagicDropTargetBehavior = function(element)

    {

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

    //Note: the private variable _dragDropMagic is used to hold data carried by the draggable object.

    //In fact, in this sample, this data matters little,

    //readers can take further consideration, such as exhibit this data before users or send it back to the server side

    this._dragDropMagic =new Custom.UI.DragDropMagic();

    }

    Custom.UI.MagicDropTargetBehavior.prototype =

    {

    // implement methods of the IDropTarget interface

    get_dropTargetElement: function()

    {

    return this.get_element();

    },

    canDrop: function(dragMode, dataType, data)

    {

    //only the two conditions are met, can the draggable object be droppable

    return (dataType == 'DragDropMagic' && data);

    },

    //do the factual dropping. Here, we use the data in the draggble object to alter the background color of the droppable area and show the dot number of the dice

    drop: function(dragMode, dataType, data)

    {

    if (dataType == 'DragDropMagic' && data)

    {

    this.get_element().style.backgroundColor = data.backgroundColor;

    this.get_element().innerHTML = data.number;

    }

    },

    //invoke this method when the draggable object is within the droppable area

    onDragEnterTarget: function(dragMode, dataType, data)

    {

    if (dataType == 'DragDropMagic' && data)

    {

    this._dragDropMagic =data;//store the data

    //use the data to modify the background color of the droppable box and the dot number of the dice

    this.get_element().style.backgroundColor = data.backgroundColor;

    this.get_element().innerHTML = data.number;

    }

    },

    onDragLeaveTarget: function(dragMode, dataType, data)

    {

    //restore the initial content

    if (dataType == 'DragDropMagic' && data)

    {

    this.get_element().style.backgroundColor =this._dragDropMagic.backgroundColor;

    this.get_element().innerHTML =this._dragDropMagic.number;

    }

    },

    //unused, then empty

    onDragInTarget: function(dragMode, dataType, data) {},

    initialize: function()

    {

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

    Sys.Preview.UI.DragDropManager.registerDropTarget(this);

    },

    dispose: function()

    {

    Sys.Preview.UI.DragDropManager.unregisterDropTarget(this);

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

    }

    }

    Custom.UI.MagicDropTargetBehavior.registerClass

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

    Sys.Preview.UI.IDropTarget);

    Since we have made enough comments between the lines, we don't need to waste space chattering. However, the last point readers should take notice of is that both in the initializeanddispose methods,the corresponding methods of DragDropManager are invoked.

    Last but not least, please remember to call the notifyScriptLoaded() methodof Sys.Application at the end of thecustDragDrop.js fileto notify theASP.NET AJAXclient-side framework that this script has been loaded successfully:

    if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();

    Next, let’s start to consider the design of the web page for the dice game.

    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...





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