Silverlight

It's been a long time since I have posted anything new, I've been too busy studying for the MCPD and learning the new features of .NET 3.5 and Silverlight.

I'm going to be posting a bunch of examples I have created with silverlight and .NET 3.5.

The snippet below is a nice javascript object which will move objects around your canvas allowing you to drag and drag and throw.


// File: Movement.js
PointMap.Movement = function(s, noderef) {
this.noderef = noderef;
this.time_to_move=0.6;
var plugin = s;
this.main = s.findName("Page")
this.loader_bar=200;
this.stage_wid=800;
this.friction=0.93;
this.init_opacity=0.95;
this.img_wid=200;
this.scroll_amount=10;
this.time_to_move=500; //in ms
this.cur_img=0;
this.num_images_loaded=0;
this.prev_wid=0;
this._root_xmouse=0;
this._root_ymouse=0;
this.scaleUpInt=0;
this.mouseCheckInt=0;
this.cur_node0X=0;
this.cur_node0Y=0;
this.img_scaling=false;
this.point1X = 0;
this.point1Y = 0;
this.point2X = 0;
this.point2Y = 0;
this.start_time = 0;
this.main_mouse_down = false;
this.p3X = 0;
this.p3Y = 0;
this.start_scale_time = 0;
setInterval(Silverlight.createDelegate(this, this.node0Tracker),10)
}
PointMap.Movement.prototype =
{
mainDown : function(s,e) {
var pt = e.getPosition(null);
clearInterval(this.scaleUpInt)
this.point1X=pt.X
this.point1Y=pt.Y
this.start_time=new Date().getTime()
var node0Ref=s.findName(this.noderef)
this.main_mouse_down=true
this.cur_node0X=node0Ref["Canvas.Left"]
this.cur_node0Y = node0Ref["Canvas.Top"];
s.captureMouse()
},
mainUp: function (s,e) {
var pt = e.getPosition(null);
this.main_mouse_down=false
this.point2X=pt.X
this.point2Y=pt.Y
//alert(point2Y)
this.chkX=Math.abs(this.point2X-this.point1X)
this.chkY=Math.abs(this.point2Y-this.point1Y)
//alert([chkX,chkY])
if(this.chkY<600 && this.chkX<600) {
this.end_time=new Date().getTime()
var elapsed=this.end_time-this.start_time
//alert(elapsed)
if(elapsed<220) {
this.p3Y=this.point2Y-this.point1Y
this.p3X=this.point2X-this.point1X
}
}
s.releaseMouseCapture()
},
mainMouseMove : function (s, e) {
var pt = e.getPosition(null);
this._root_xmouse = pt.x
this._root_ymouse = pt.y
},
node0Tracker : function() {
var check_zeroX = Math.abs(this.p3X)
this.end=0.7
var node0Ref=this.main.findName(this.noderef)
this.diff=this.prev_wid-this.stage_wid
if(this.main_mouse_down) {
var newleft = this.cur_node0X-(this.point1X-this._root_xmouse);
var newtop = this.cur_node0Y-(this.point1Y-this._root_ymouse);
if (newleft < 500) {
node0Ref["Canvas.Left"]=newleft;

}
if (newtop < 500) {
node0Ref["Canvas.Top"]=newtop;

}
this.lineTracker(node0Ref);
}
if(check_zeroX>this.end) {
if(!this.main_mouse_down) {
var newX = node0Ref["Canvas.Left"]+this.p3X/3.2;
var newY = node0Ref["Canvas.Top"]+=this.p3Y/3.2;
if (newX < 500){
node0Ref["Canvas.Left"]=newX;

}
if (newY<500) {
node0Ref["Canvas.Top"]=newY;

}
this.p3X*=this.friction
this.p3Y*=this.friction
this.lineTracker(node0Ref);
}
else {
this.p3X=0
this.p3Y=0
}
}
},
mouseChecker : function (s,me) {
if(this.img_mouse_down) {
s["Canvas.Left"]=this._root_xmouse-this.img_offset_x
s["Canvas.Top"]=this._root_ymouse-this.img_offset_y
}
}
}
}