Humanitarian plane

Code Actionscript 2.0

Frame action

onMouseDown = function() {
package.speedy = 5.0;
package._y = plane._y;
package._visible = true;
}

Instance action

onClipEvent(load) {
speedy=0;
this._y= _parent.plane._y;
this._visible = false;
}

on (press) {
speedy = 5.0;
this._y = _parent.plane._y;
this._visible = true;
}

onClipEvent(enterFrame) {
// care-package moves with plane
this._x = _parent.plane._x;

// falling movement of care-package
this._y = this._y + speedy;

// reset
if (this._y > 410) {
trace("miss");
this._y=_parent.plane._y;
this._visible = false;
speedy = 0;
}
}

Instance action

onClipEvent (load) {
speedx=3;
}

onClipEvent (enterFrame) {
// movement of plane
this._x = this._x+speedx;

// if planes leaves stage, restart at left edge
if (this._x > 440) {
this._x = -40;
}
}

Instance action

onClipEvent (enterFrame) {
// if care package was caught
if (this.hitTest (_parent.package)) {
trace ("thank you!");
this._alpha = 40;

// hide package
_parent.package._visible = false;
_parent.package._y = _parent.plane._y;
_parent.package.speedy = 0;
} else {
this._alpha = 100;
}
}

Code Actionscript 3.0

addEventListener(Event.ENTER_FRAME, enterFrame); stage.addEventListener(MouseEvent.MOUSE_DOWN, press); var speedx=3; var speedy=0; package1.y= plane.y; package1.visible = false; function press(e:MouseEvent){ speedy = 5; package1.y= plane.y; package1.visible = true; } function enterFrame(event:Event) { // movement of plane plane.x = plane.x+speedx; // if planes leaves stage, restart at left edge if (plane.x > 440) { plane.x = -40; } // care-package moves with plane package1.x = plane.x; // falling movement of care-package package1.y = package1.y + speedy; // reset if (package1.y > 410) { trace("miss"); package1.y= plane.y; package1.visible = false; speedy = 0; } // if care package was caught if (receiver.hitTestObject (package1)) { trace ("thank you!"); receiver.alpha = 0.4; // hide package package1.visible = false; package1.y = plane.y; package1.speedy = 0; } else { receiver.alpha = 1; } }

Description

A plane has the task of dropping relief supplies onto the target location. The script from the example "Drop off" reveals the supplies package when the mouse is pressed. Falling at a constant speed and angle from the position it was dropped, the target will change color if the two collide.

related to: Bouncing movement, Collision, Drop off

Download

Right click: Flashfile AS 2.0 | Flashfile AS 3.0 | SWF-File


Share