私はベテランのアクションスクリプトコーダーで、JavaScriptで最初のスタブをとっています。ほとんどの場合、それほど複雑ではありませんが、トグルのような多数のボタンを作成しているので、いくつかの問題にぶつかりました。これまでのコードはここにあります(私はそれらの束を削除しましたが、約5つではなく約20種類あります)。アニメーションCC HTML5が文字列を呼び出してグローバル変数を変更しようとしています
var aOneOn = false;
var aTwoOn = false;
var aThreeOn = false;
var aFourOn = false;
var aFiveOn = false;
this.One.addEventListener("click", highlightButton.bind(this));
this.Two.addEventListener("click", highlightButton.bind(this));
this.Three.addEventListener("click", highlightButton.bind(this));
this.Four.addEventListener("click", highlightButton.bind(this));
this.Five.addEventListener("click", highlightButton.bind(this));
function highlightButton(event)
{
console.log("You have selected a button " + event.currentTarget.name); //Three
var newName = "a" + event.currentTarget.name + "On";
console.log("the buttons new name is " + newName); //aThreeOn
console.log("the correct answer is " + aTwoOn); //false
console.log("the button is currently " + this[newName]); //undefined
if(this[newName] == true)
{
console.log("we should be turning it false now");
this[newName] = false;
}
else if (this[newName] == false)
{
console.log("we should be turning it true now");
this[newName] = true;
}
console.log("the button " + newName + " is now " + this[newName]);
}
これはNEWNAMEは、二つのボタンを押す、またはボタンのいずれかが、私が期待したように機能しているときに実際にaTwoOnにアクセスできることにはなりません。私はそれが範囲になると何かを見逃しているが、何をする必要があるのか分からないように思える。
このnoobieに何か助けていただきありがとうございます。
私はそれがevent.currentTarget.name
は
undefined
であることが判明した場合、その後、
newName
は
var newName = "aundefinedOn";
に評価され、それはあるかもしれないラインで
var newName = "a" + event.currentTarget.name + "On";
を行うために何かを持って考えています
あなたは何が起こっているのか記述できますか? –
確かに...ゲームでは、20のボタンで練習しなければならない20種類の問題を選択します。ボタンをクリックすると、ハイライト表示されます。再度クリックすると強調表示されません。そして、練習したいものをすべて選択したら、完了ボタンを押します。コードのこの部分は、基本的にさまざまなオプションのオンとオフを切り替えるものです。彼らが完了したら、それは通過して、どちらがオンであるかを見て、それらを問題のリストに加えます。希望は意味をなさない。 – TixxiumQ
@NatashaOliver 'HTML' please –