Saturday, January 3, 2009

ग्राविटी बल कोड फॉर एक्शन script

code by anil nain for flash action script anil nain is software enginearonSelfEvent(load){ var air_fy: Number = 10; var air_fx: Number = 10; var gravity: Number = 150; var intial_vy: Number = 20; var num_balls: Number = 3; var old_num: Number = 0; var ball_elastic: Number = 0.7; }onFrame(2){ for(db= (1); db<=old_num; db++){ this["ball_"+db].removeMovieClip(); } ball_mc._visible = false; for(ib =1;ib <=num_balls; ib++){ // duplicate ball_mc var add_ball: String = "ball_"+ib; ball_mc.duplicateMovieClip(add_ball,10+ib); var new_ball_mc: Object = this[add_ball]; new_ball_mc.txt_field.text = ib; var new_x2: Number = ((Stage.width - 200)/(num_balls))*ib; new_ball_mc._x = new_x2; new_ball_mc._y = 50; new_ball_mc._vy = intial_vy; new_ball_mc._ay = gravity; new_ball_mc.new_vy = intial_vy; new_ball_mc.new_ay = gravity; new_ball_mc.new_vx = 0; new_ball_mc.new_ax = 0; new_ball_mc._fy = air_fy; new_ball_mc._fx = air_fx; apply_color(new_ball_mc,ib); new_ball_mc._visible = true; } }onFrame(3){ stop(); }function apply_color(what_ball, num_b){ // the colors are hexidecimal numbers with '0x' added to let the script understand that it is a hexidecimal
color; // note: I have only setup 6 colors for 6 balls. You will need to add more numbers, use the color select in the
properties // panel to see the hexidecimal number of a color you like. if(num_b == 1){ var ball_c: Object = new Color(what_ball.shape_mc); ball_c.setRGB(0xff0000); } else if(num_b == 2){ var ball_c: Object = new Color(what_ball.shape_mc); ball_c.setRGB(0x00ff00); } else if(num_b == 3){ var ball_c: Object = new Color(what_ball.shape_mc); ball_c.setRGB(0xfff000); } else if(num_b == 4){ var ball_c: Object = new Color(what_ball.shape_mc); ball_c.setRGB(0x0000ff); } else if(num_b == 5){ var ball_c: Object = new Color(what_ball.shape_mc); ball_c.setRGB(0xff00ff); } else if(num_b == 6){ var ball_c: Object = new Color(what_ball.shape_mc); ball_c.setRGB(0x0000ff); } else { var ball_c: Object = new Color(what_ball.shape_mc); ball_c.setRGB(0x000fff); }}



spring slider


onSelfEvent(load){
var inital_n: Number = _root.ball_elastic; var min_n: Number = 0; var max_n: Number = 1; var inital_pos: Number = ((inital_n/(max_n - min_n)) * (slider.small_rect._width - slider.slider_bn._width)) +
slider.small_rect._x; slider.slider_bn._x = inital_pos; slider.txt_n.text = inital_n; // var intial_object: Object = _parent._parent.gravity; ref_var = intial_object; slider.slider_bn.onPress = function(){ record_pos(_parent._parent.gravity, max_n, min_n); // Here the horizontal movement of the slider_bn // dragging state is locked the width and position of the 1 // small_rect. The vertical move is zero, so we used the intial // position of the slider_bn this.startDrag(false, this._parent.small_rect._x, this._y, (this._parent.small_rect._x +
this._parent.small_rect._width - this.slider_bn._width), this._y); } slider.slider_bn.onRelease = function(){ recorder.removeMovieClip(); slider_bn.stopDrag(); } slider.slider_bn.onReleaseOutside = function(){ slider_bn.stopDrag(); }
}function record_pos(ref_var1,max_n,min_n){ createEmptyMovieClip("recorder",10); recorder.onEnterFrame = function(){ var current_ratio: Number = ((_parent.slider.slider_bn._x -
_parent.slider.small_rect._x)/(_parent.slider.small_rect._width - _parent.slider.slider_bn._width)) * (max_n -
min_n); _parent.slider.txt_n.text = (current_ratio); // apply to the var for that slider _root.ball_elastic = current_ratio; } }
numball slider
onSelfEvent(load){ var inital_n: Number = _root.num_balls; var min_n: Number = 0; var max_n: Number = 10; var inital_pos: Number = Math.ceil((inital_n/(max_n - min_n)) * (slider.small_rect._width -
slider.slider_bn._width)) + slider.small_rect._x; slider.slider_bn._x = inital_pos; slider.txt_n.text = inital_n; // var intial_object: Object = _parent._parent.gravity; ref_var = intial_object; slider.slider_bn.onPress = function(){ record_pos(_parent._parent.gravity, max_n, min_n); // Here the horizontal movement of the slider_bn // dragging state is locked the width and position of the 1 // small_rect. The vertical move is zero, so we used the intial // position of the slider_bn this.startDrag(false, this._parent.small_rect._x, this._y, (this._parent.small_rect._x +
this._parent.small_rect._width - this.slider_bn._width), this._y); } slider.slider_bn.onRelease = function(){ recorder.removeMovieClip(); slider_bn.stopDrag(); } slider.slider_bn.onReleaseOutside = function(){ slider_bn.stopDrag(); }
}function record_pos(ref_var1,max_n,min_n){ createEmptyMovieClip("recorder",10); recorder.onEnterFrame = function(){ var current_ratio: Number = ((_parent.slider.slider_bn._x -
_parent.slider.small_rect._x)/(_parent.slider.small_rect._width - _parent.slider.slider_bn._width)) * (max_n -
min_n); _parent.slider.txt_n.text = Math.ceil(current_ratio); // apply to the var for that slider _root.num_balls = Math.ceil(current_ratio); } }


air resistant
onSelfEvent(load){ var inital_n: Number = _root.air_fy; var min_n: Number = 0; var max_n: Number = 100; var inital_pos: Number = Math.ceil((inital_n/(max_n - min_n)) * (slider.small_rect._width -
slider.slider_bn._width)) + slider.small_rect._x; slider.slider_bn._x = inital_pos; slider.txt_n.text = inital_n; // var intial_object: Object = _parent._parent.gravity; ref_var = intial_object; slider.slider_bn.onPress = function(){ record_pos(_parent._parent.gravity, max_n, min_n); // Here the horizontal movement of the slider_bn // dragging state is locked the width and position of the 1 // small_rect. The vertical move is zero, so we used the intial // position of the slider_bn this.startDrag(false, this._parent.small_rect._x, this._y, (this._parent.small_rect._x +
this._parent.small_rect._width - this.slider_bn._width), this._y); } slider.slider_bn.onRelease = function(){ recorder.removeMovieClip(); slider_bn.stopDrag(); } slider.slider_bn.onReleaseOutside = function(){ slider_bn.stopDrag(); }
}function record_pos(ref_var1,max_n,min_n){ createEmptyMovieClip("recorder",10); recorder.onEnterFrame = function(){ var current_ratio: Number = ((_parent.slider.slider_bn._x -
_parent.slider.small_rect._x)/(_parent.slider.small_rect._width - _parent.slider.slider_bn._width)) * (max_n -
min_n); _parent.slider.txt_n.text = Math.ceil(current_ratio); // apply to the var for that slider _root.air_fy = current_ratio; } }
gravity
onSelfEvent(load){ var inital_n: Number = _root.gravity; var min_n: Number = 0; var max_n: Number = 300; var inital_pos: Number = Math.ceil((inital_n/(max_n - min_n)) * (slider.small_rect._width -
slider.slider_bn._width)) + slider.small_rect._x; slider.slider_bn._x = inital_pos; slider.txt_n.text = inital_n; // var intial_object: Object = _parent._parent.gravity; ref_var = intial_object; slider.slider_bn.onPress = function(){ record_pos(_parent._parent.gravity, max_n, min_n); // Here the horizontal movement of the slider_bn // dragging state is locked the width and position of the 1 // small_rect. The vertical move is zero, so we used the intial // position of the slider_bn this.startDrag(false, this._parent.small_rect._x, this._y, (this._parent.small_rect._x +
this._parent.small_rect._width - this.slider_bn._width), this._y); } slider.slider_bn.onRelease = function(){ recorder.removeMovieClip(); slider_bn.stopDrag(); } slider.slider_bn.onReleaseOutside = function(){ slider_bn.stopDrag(); }
}function record_pos(ref_var1,max_n,min_n){ createEmptyMovieClip("recorder",10); recorder.onEnterFrame = function(){ var current_ratio: Number = ((_parent.slider.slider_bn._x -
_parent.slider.small_rect._x)/(_parent.slider.small_rect._width - _parent.slider.slider_bn._width)) * (max_n -
min_n); _parent.slider.txt_n.text = Math.ceil(current_ratio); // apply to the var for that slider _root.gravity = current_ratio; } }
collection tester
onSelfEvent(load){ var inital_n: Number = _root.gravity; var min_n: Number = 0; var max_n: Number = 300; var inital_pos: Number = Math.ceil((inital_n/(max_n - min_n)) * (slider.small_rect._width -
slider.slider_bn._width)) + slider.small_rect._x; slider.slider_bn._x = inital_pos; slider.txt_n.text = inital_n; // var intial_object: Object = _parent._parent.gravity; ref_var = intial_object; slider.slider_bn.onPress = function(){ record_pos(_parent._parent.gravity, max_n, min_n); // Here the horizontal movement of the slider_bn // dragging state is locked the width and position of the 1 // small_rect. The vertical move is zero, so we used the intial // position of the slider_bn this.startDrag(false, this._parent.small_rect._x, this._y, (this._parent.small_rect._x +
this._parent.small_rect._width - this.slider_bn._width), this._y); } slider.slider_bn.onRelease = function(){ recorder.removeMovieClip(); slider_bn.stopDrag(); } slider.slider_bn.onReleaseOutside = function(){ slider_bn.stopDrag(); }
}function record_pos(ref_var1,max_n,min_n){ createEmptyMovieClip("recorder",10); recorder.onEnterFrame = function(){ var current_ratio: Number = ((_parent.slider.slider_bn._x -
_parent.slider.small_rect._x)/(_parent.slider.small_rect._width - _parent.slider.slider_bn._width)) * (max_n -
min_n); _parent.slider.txt_n.text = Math.ceil(current_ratio); // apply to the var for that slider _root.gravity = current_ratio; } }
ball mc
onSelfEvent(load){ var time_d1 : Object = new Date() var time_t1: Number = time_d1.getTime(); var pos_x1: Number = this._x; var pos_y1: Number = this._y; var dragging: Boolean = false; var collision: Boolean = false;} onSelfEvent(enterFrame){ if(dragging){ //sample the positions to determine the release velocities; // // first measure the changes in position and time past. var time_d2 : Object = new Date(); var time_t2: Number = time_d2.getTime(); var time_diff: Number = time_t2 - time_t1; var time_t1: Number = time_t2; // var pos_x2: Number = this._x; var pos_y2: Number = this._y; var diff_x: Number = pos_x2 - pos_x1; var diff_y: Number = pos_y2 - pos_y1; var pos_x1: Number = pos_x2; var pos_y1: Number = pos_y2; // var new_vx: Number = (diff_x * time_diff); var new_vy: Number = (diff_y * time_diff); } }
onSelfEvent(press){ this.startDrag(false,this._width/2,this._height/2,Stage.width-(this._width/2),Stage.height -(this._height/2));
var dragging: Boolean = true; this._vx = 0; this._vy = 0; this._ax = 0; this._ay = 0; }onSelfEvent(release, releaseOutside){ this.stopDrag(); var dragging: Boolean = false; this._vx = new_vx; this._vy = new_vy; this._ay = _root.gravity; this._fy = _root.air_fy; this._fx = _root.air_fx;}

No comments: