Ads by Google

--年--月--日 --:--

上記の広告は1ヶ月以上更新のないブログに表示されています。
新しい記事を書く事で広告が消せます。

ドラッグ操作についてのAS3.0

2008年07月26日 11:04

ドラッグ操作はかなり使う頻度が高い(と思う)し、AS3.0になってスクリプトも変わったのでメモ。

まずはごく単純にドラッグ操作のみのスクリプト。

This text is replaced by the Flash movie.

box1.buttonMode = true;//MCをボタンMCのようにカーソルを変えます。

box1.addEventListener(MouseEvent.MOUSE_DOWN, boxStartDrag);
box1.addEventListener(MouseEvent.MOUSE_UP, boxStopDrag);

function boxStartDrag(event:MouseEvent):void {
box1.startDrag();//引数は未記述
}
function boxStopDrag(event:MouseEvent):void {
box1.stopDrag();
}

さらに、ドラッグ範囲を指定したい場合は、startDrag()に引数を設定します。

This text is replaced by the Flash movie.

box1.buttonMode = true;//MCをボタンMCのようにカーソルを変えます。

//ドラッグ範囲のプロパティ
var rec:Rectangle = new Rectangle(20, 20, 180, 10);

box1.addEventListener(MouseEvent.MOUSE_DOWN, boxStartDrag);
box1.addEventListener(MouseEvent.MOUSE_UP, boxStopDrag);

function boxStartDrag(event:MouseEvent):void {
box1.startDrag(false, rec);//第2引数に設定したRectangleを入れます。
}
function boxStopDrag(event:MouseEvent):void {
box1.stopDrag();
}

【解説】
startDrag()の第1引数はBooleanなので、"true"か"false"になります。
"true"の場合はドラッグ操作をしようとした瞬間にクリックした場所にMCの中心がロックします。"false"の場合はそれがありません。

This text is replaced by the Flash movie.

第2引数はドラッグ設定したドラッグ範囲を入れます。
Rectangleの設定は(範囲のx座標,範囲のy座標,範囲の横幅,範囲の縦幅)となっています。


コメント

    コメントの投稿

    (コメント編集・削除に必要)
    (管理者にだけ表示を許可する)

    トラックバック

    この記事のトラックバックURL
    http://lifepad2.blog39.fc2.com/tb.php/2-ee51f7aa
    この記事へのトラックバック