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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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 / 10
    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


    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

    - Develop Your First ASP.NET Website with Visu...
    - Run ASP.NET in Windows XP Home with Cassini ...
    - How to Test a Web Application
    - How to Add Code and Validation Controls to a...
    - Working in Source and Split Views to Build a...
    - How to Build a Web Form for a One-Page Web A...
    - How to Develop a One-Page Web Application
    - An ASP.NET Web Application in Action
    - Developing ASP.NET Web Applications
    - An Introduction to ASP.NET Web Programming
    - Introduction to the ADO.NET Entity Framework...
    - Completing an In-Text Advertising System und...
    - Programming an In-Text Advertising System un...
    - Building an In-Text Advertising System Under...
    - Developing a Mini ASP.NET AJAX Server Centri...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT