Webサイト制作科 - 作品紹介

Webサイト制作科 - 作品紹介

匿名関数-スロット

イベントハンドラ

  • イベントハンドラ」は、ムービー再生中に発生するイベントを感知する
  • オブジェクトに命令する動作内容を自由に作ることができる「メソッド」の一種



onRelease
オブジェクトがクリックされたとき〜する


onRollOver
オブジェクトの上にポインタが乗った状態のとき〜する


onKeyDown
あるキーが押されたとき〜する


ムービークリップイベントハンドラメソッド
イベント 説明
onLoad onClipEvent ( load ) ハンドラのイベントハンドラメソッド
onUnload onClipEvent ( unLoad ) ハンドラのイベントハンドラメソッド
onEnterFrame onClipEvent ( enterFrame ) ハンドラのイベントハンドラメソッド
onMouseDown onClipEvent ( mouseDown ) ハンドラのイベントハンドラメソッド
onMouseUp onClipEvent ( mouseUp ) ハンドラのイベントハンドラメソッド
onMouseMove onClipEvent ( mouseMove ) ハンドラのイベントハンドラメソッド
onKeyDown onClipEvent ( keyDown ) ハンドラのイベントハンドラメソッド
onKeyUp onClipEvent ( keyUp ) ハンドラのイベントハンドラメソッド
onData onClipEvent ( data ) ハンドラのイベントハンドラメソッド


ボタンのイベントハンドラメソッド
onPress on ( press ) ハンドラのイベントハンドラメソッド
onRelease on ( release ) ハンドラのイベントハンドラメソッド
onReleaseOutside on ( releaseOutside ) ハンドラのイベントハンドラメソッド
onRollOut on ( rollOut ) ハンドラのイベントハンドラメソッド
onRollOver on ( rollOver ) ハンドラのイベントハンドラメソッド
onDragOut on ( dragOut ) ハンドラのイベントハンドラメソッド
onDragOver on ( dragOver ) ハンドラのイベントハンドラメソッド
onKillFocus インスタンスがフォーカスを失った。
onSetFocus インスタンスがフォーカスを受け取った。

イベントハンドラメソッド
  • 関数名がないことから関数式で定義した関数


ActionScriptでは

data.onLoad = function() {
	/*データが読み込まれたときの処理*/
}


JavaScriptでは

window.onload = function() {
	/*画面が読み込まれたときの処理*/
}


《例》

描画

ボタン

  • Flashの描画機能を使う(ビットマップ)
  • Illustratorからコンバートする(各パーツをすべて描いてから「ボタンシンボル内」にコピー&ペースト)
  • スタートボタンを複製してストップボタンをつくる(着色では色が濁るので、別の色を選択します)
  • リスタートボタンも作る


カウンター

  • タイムライン上に配置

ステージに配置
  • ステージ幅「幅500、高さ300」(プロパティで変更)
  • レイヤーごとに配置する

Actionを記述
  1. Flashムービーは、停止させなければ自動再生する(まず止める)
  2. スタートボタンが押されたら、各カウンターが動く
  3. ストップボタンが押されたら、対応するカウンターが停止する
  4. リセットボタンでカウンターを「0」に戻す


《最も単純な記述》

onLoad = function() {
	num01_mc.stop();
	num02_mc.stop();
	num03_mc.stop();
}
start_btn.onPress = function() {
	num01_mc.play();
	num02_mc.play();
	num03_mc.play();
}
stop01_btn.onPress = function() {
	num01_mc.stop();
}
stop02_btn.onPress = function() {
	num02_mc.stop();
}
stop03_btn.onPress = function()
{
	num03_mc.stop();
}
reset_btn.onRelease = function() {
	num01_mc.gotoAndStop(1);
	num02_mc.gotoAndStop(1);
	num03_mc.gotoAndStop(1);
}


《_rootで記述》

this.onLoad = function() {
	this.num01_mc.stop();
	this.num02_mc.stop();
	this.num03_mc.stop();
}
this.start_btn.onPress = function() {
	_root.num01_mc.play();
	_root.num02_mc.play();
	_root.num03_mc.play();
}
this.stop01_btn.onPress = function() {
	_root.num01_mc.stop();
}
this.stop02_btn.onPress = function() {
	_root.num02_mc.stop();
}
this.stop03_btn.onPress = function()
{
	_root.num03_mc.stop();
}
this.reset_btn.onRelease = function() {
	_root.num01_mc.gotoAndStop(1);
	_root.num02_mc.gotoAndStop(1);
	_root.num03_mc.gotoAndStop(1);
}


《_parentで記述》

this.onLoad = function() {
	this.num01_mc.stop();
	this.num02_mc.stop();
	this.num03_mc.stop();
}
this.start_btn.onPress = function() {
	this._parent.num01_mc.play();
	this._parent.num02_mc.play();
	this._parent.num03_mc.play();
}
this.stop01_btn.onPress = function() {
	this._parent.num01_mc.stop();
}
this.stop02_btn.onPress = function() {
	this._parent.num02_mc.stop();
}
this.stop03_btn.onPress = function()
{
	this._parent.num03_mc.stop();
}
this.reset_btn.onRelease = function() {
	this._parent.num01_mc.gotoAndStop(1);
	this._parent.num02_mc.gotoAndStop(1);
	this._parent.num03_mc.gotoAndStop(1);
}


《ユーザー定義関数で記述》

this.onLoad = function() {
	this.num01_mc.stop();
	this.num02_mc.stop();
	this.num03_mc.stop();
}
function toPlay():Void {
	this._parent.num01_mc.play();
	this._parent.num02_mc.play();
	this._parent.num03_mc.play();
}
function toStop1():Void {
	this._parent.num01_mc.stop();
}
function toStop2():Void {
	this._parent.num02_mc.stop();
}
function toStop3():Void {
	this._parent.num03_mc.stop();
}
function toReset():Void {
	this._parent.num01_mc.gotoAndStop(1);
	this._parent.num02_mc.gotoAndStop(1);
	this._parent.num03_mc.gotoAndStop(1);
}
this.start_btn.onPress = toPlay;
this.stop01_btn.onPress = toStop1;
this.stop02_btn.onPress = toStop2;
this.stop03_btn.onPress = toStop3;
this.reset_btn.onRelease = toReset;