ActionScriptでドラッグして投げるサンプル。
function Ball() {
var oldX;
var oldY;
var vx = 0;
var vy = 0;
this.init = function() {
this.onEnterFrame = moving;
};
this.onPress = function() {
oldX = this._x;
oldY = this._y;
this.startDrag(false);
delete this.onEnterFrame;
this.onEnterFrame = tracing;
};
this.onRelease = function() {
this.stopDrag();
delete this.onPress;
delete this.onEnterFrame;
this.onEnterFrame = moving;
};
this.onReleaseOutside = function() {
this.stopDrag();
delete this.onPress;
delete this.onEnterFrame;
this.onEnterFrame = moving;
};
var tracing = function () {
vx = this._x-oldX;
vy = this._y-oldY;
oldX = this._x;
oldY = this._y;
};
var moving = function () {
this._x += vx;
this._y += vy;
};
}
var o = new Ball();
var mc = _root.attachMovie('ball', 'ball', _root.getNextHighestDepth(), o);
mc.init();
※onReleaseOutsideメソッドを記述しないと正常に動作しない。
No comments yet.
改行と段落タグは自動で挿入されます。
メールアドレスは表示されません。