タグ: 未設定

ドラッグして投げる : ActionScript2.0

投稿日 : 2008年6月1日 | 更新日 : 2010年12月07日 前のページへ戻る

ActionScriptでドラッグして投げるサンプル。

流れ

  1. 幅:20,高さ:20の円を描画(Shift+ドラッグで真丸の円)。
  2. ムービークリップシンボルへ変換(F8)。変換ダイアログのオプションを下記のように設定。
    名前: ball
    識別子: ball
    リンケージ:ActionScriptへ書き出し: 最初のフレームへ書き出し
  3. 円はActionScriptのattachMovie関数で動的に書き出すため、ステージから削除。
  4. 1フレーム目に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メソッドを記述しないと正常に動作しない。

ActionScript2.0 | 固定リンク | Comments (0)

関連記事

    関連記事は見つかりませんでした。
    検索ボックスからの検索もお試しください。

このページの上へ移動

コメント

コメントはまだありません。

コメントの投稿

改行と段落タグは自動で挿入されます。
メールアドレスは表示されません。

 

 

 


トラックバックURL

http://www.findxfine.com/flash/actionscript/393.html/trackback

このページの上へ