カードの目隠し「blindfold」を非表示にしてカードをめくる
1. レイヤー「action」の2フレーム目に以下のActionscriptを記述してください。clickCount = 0;
for(i = 0;i < 12;i++){
_root["cards" + i].onRelease = function(){
this.blindfold._visible =false;
trace("clickCount" + clickCount);
if(clickCount == 0){
question(this,this._currentframe);
}else{
answer(this,this._currentframe);
}
}
}
function question(i,j){
clickCount++;
questionCard = i;
questionColor = j;
}
function answer(i,j){
answerCard = i;
answerColor = j;
clickCount= 0;
play();
}
stop();
少し長いので分割して見ていきましょう。clickCount = 0;
for(i = 0;i < 12;i++){
_root["cards" + i].onRelease = function(){
this.blindfold._visible =false;
if(clickCount == 0){
question(this,this._currentframe);
}else{
answer(this,this._currentframe);
}
}
}
まず、前半の部分について見ていきます。1行目の変数「clickCount」は、2枚ずつめくっていくカードのクリックされた回数を管理させるものです。例えば最初にクリックした場合は「0」、二回目にクリックした場合は「1」を入力します。
2行目からは先程同様のfor文です。カード12枚にそれぞれ同様の機能を割りつけています。
次のページではカードの正解・不正解をチェックする機能を作ります。






